-
Notifications
You must be signed in to change notification settings - Fork 78
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
cartesianToCompressed changed to unordered multimap #687
base: master
Are you sure you want to change the base?
Conversation
jenkins build this serial please |
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.
Just a couple of minor points now, as an initial review. I haven't thought through the full implications of using using unordered_multimap<>
here. Another option might be
unordered_map<int,std::vector<int>>
instead.
retval.reserve(num_cells); | ||
if (global_cell) { | ||
for (int i = 0; i < num_cells; ++i) { | ||
retval.insert(std::pair<int,int>(global_cell[i], i)); | ||
} | ||
} else { | ||
for (int i = 0; i < num_cells; ++i) { | ||
retval.insert(std::pair<int,int>(i, i)); | ||
} | ||
return retval; | ||
} | ||
return retval; |
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.
If you're changing this anyway, now would be a good time to switch to
retval.emplace(x, y)
instead of
retval.insert(std::pair<int,int>(x, y))
They do the same thing, effectively, but the former (.emplace()
) is (slightly) faster since it constructs the value in-place.
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.
Thanks for your feedback! Indeed, unordered_map<int, std::vector> is an alternative too. I'll check it out.
for (const auto pair : cartesian_to_compressed) | ||
{ | ||
std::cout << pair.first << " " << pair.second << '\n'; | ||
} |
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.
Is this code left over from development? If so, I think we should remove it.
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.
Opps! Yes, that was supposed to be removed. Thanks for noticing!
94769bd
to
db56d39
Compare
When a CpGrid has LGRs, a Cartesian index (key) is associated to more than one compressed index (value). Therefore, this unordered_map now has been replaced by an unordered_multimap, to support multiple value with a same key.