-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Doc comments: use std::unordered_map #11113
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,12 +2,15 @@ | |
|
|
||
| #include <cinttypes> | ||
|
|
||
| #include "util.hh" | ||
|
|
||
| namespace nix { | ||
|
|
||
| class PosIdx | ||
| { | ||
| friend struct LazyPosAcessors; | ||
| friend class PosTable; | ||
| friend class std::hash<PosIdx>; | ||
|
|
||
| private: | ||
| uint32_t id; | ||
|
|
@@ -37,8 +40,28 @@ public: | |
| { | ||
| return id == other.id; | ||
| } | ||
|
|
||
| size_t hash() const noexcept | ||
| { | ||
| size_t h = 854125; | ||
| hash_combine(h, id); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| return h; | ||
| } | ||
| }; | ||
|
|
||
| inline PosIdx noPos = {}; | ||
|
|
||
| } | ||
|
|
||
| namespace std { | ||
|
|
||
| template<> | ||
| struct hash<nix::PosIdx> | ||
| { | ||
| std::size_t operator()(nix::PosIdx pos) const noexcept | ||
| { | ||
| return pos.hash(); | ||
| } | ||
| }; | ||
|
|
||
| } // namespace std | ||
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: