-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Doc comments: use std::unordered_map #11113
Conversation
Co-authored-by: Eelco Dolstra <[email protected]>
src/libexpr/pos-idx.hh
Outdated
@@ -2,12 +2,15 @@ | |||
|
|||
#include <cinttypes> | |||
|
|||
#include "util.hh" |
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 this included?
Can't seem to tell.
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 asking. It was for hash_combine
, but that wasn't obvious at all.
I've split that into its own header, partly because "util" is a bad scope for a header, but also for the less subjective argument, from the commit message:
Splitting it out immediately answers questions like [this], without increasing the number of compilation units.
I did consider using boost::hash_combine instead, but it doesn't seem to be quite as capable, accepting only two arguments.
Splitting it out immediately answers questions like [this], without increasing the number of compilation units. I did consider using boost::hash_combine instead, but it doesn't seem to be quite as capable, accepting only two arguments. [this]: #11113 (comment)
Splitting it out immediately answers questions like [this], without increasing the number of compilation units. I did consider using boost::hash_combine instead, but it doesn't seem to be quite as capable, accepting only two arguments. [this]: #11113 (comment)
fcdcffd
to
d0e9878
Compare
src/libexpr/pos-idx.hh
Outdated
size_t hash() const noexcept | ||
{ | ||
size_t h = 854125; | ||
hash_combine(h, id); |
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 hash_combine()
seems unnecessary? We can just return the hash of id
.
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.
In Java it's common practice to include a random number to represent the distinct type, but I think you're right.
That doesn't really apply here, because we don't have a "top" type like Java's Object
that would create a need to avoid collisions when used in e.g. HashMap<String, Object>
.
The closest thing we might have is std::variant
. I think we can assume that it hashes its index number, which is probably better than salting each type anyway, because iirc it allows multiple distinct occurrences of the same type.
In C++ we don't need to salt the hash.
Motivation
As suggested in #11072 and now possible after #11092
Context
Priorities and Process
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.