-
Notifications
You must be signed in to change notification settings - Fork 274
Make sharing map iteration independent of tree depth #4582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make sharing map iteration independent of tree depth #4582
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks ok to me, but given my judgement wasn't exactly spot-on on an earlier PR it would be great if @smowton could please review and approve.
@@ -894,6 +894,8 @@ SHARING_MAPT2(, innert *)::get_container_node(const key_type &k) | |||
key >>= chunk; | |||
} | |||
|
|||
SM_ASSERT(ip->is_container()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it not is_defined_container
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The non-const version of get_container_node()
adds empty nodes if the key doesn't exist yet in the map. In this case, !empty()
will not hold.
@@ -378,6 +378,9 @@ TEST_CASE("Sharing map views and iteration", "[core][util]") | |||
SECTION("Iterate") | |||
{ | |||
sharing_map_standardt sm; | |||
|
|||
sm.iterate([](const irep_idt &key, const std::string &value) {}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So ... what does this test other than that it compiles?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This just checks that calling iterate()
on an empty map doesn't violate an internal assertion of the map.
src/util/sharing_map.h
Outdated
std::function<void(const key_type &k, const mapped_type &m)> f) const; | ||
|
||
void gather_all(const baset &n, const unsigned depth, delta_viewt &delta_view) | ||
void gather_all(const innert &n, delta_viewt &delta_view) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format
would like the const;
on this line as well.
src/util/sharing_map.h
Outdated
|
||
for(const auto &l1 : ip1->get_container()) | ||
{ | ||
const key_type &k1=l1.get_key(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space around =
SM_ASSERT(!ip1->empty()); | ||
SM_ASSERT(!ip2->empty()); | ||
|
||
if(ip1->is_internal() && ip2->is_container()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why only this way around? Also, if a node is internal in tree 1 and a leaf in tree 2, why is it guaranteed to have a single child?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other cases are handled further down in the method.
A container node can only contain more than one element if it is at the very bottom of the tree (which happens when the hash codes of two different keys are the same). Since the corresponding node of the first map is an internal node, the node can't be at the bottom, since the bottom nodes always have to be container nodes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha, got you. Suggest putting that in a comment!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, added a comment to explain this.
d69b9bb
to
0283845
Compare
Previously the depth of a node was used to determine its type. This changes the iterate() method to use is_internal() or is_container() to determine the node type instead.
0283845
to
16dae89
Compare
This makes the various methods that iterate over a sharing map independent of the depth of the nodes in the tree. This is in preparation to support variable height trees.