Make NodeRef hashable - #408
Closed
DennisOSRM wants to merge 1 commit into
Closed
Conversation
Added `std::hash<osmium::NodeRef>` specialization (hashes `ref()` only, matching `operator==`) and unit tests for hash equality, inequality, and use in `std::unordered_set`.
- include/osmium/osm/node_ref.hpp
- Added #include <functional>
- Added std::hash<osmium::NodeRef> specialization that hashes only ref() — matching what operator== compares (ref-only). Follows the same pattern (clang pragma, argument_type/result_type) as the existing std::hash<osmium::Location> in location.hpp
- All comparison operators remain unchanged
- test/t/osm/test_node_ref.cpp
- Added #include <functional> and #include <unordered_set>
- Equality test restored to original form
- Added "Hash of NodeRefs" test case with three sections:
- Equal NodeRefs (same ref) → equal hashes
- Different refs → different hashes
- Usable in std::unordered_set
DennisOSRM
commented
Aug 4, 2026
| } | ||
|
|
||
| TEST_CASE("Equality comparison fo NodeRefs") { | ||
| TEST_CASE("Equality comparison of NodeRefs") { |
Contributor
Author
There was a problem hiding this comment.
fix of an unrelated typo ;)
Member
|
Please don't invite AI slop into this repo. |
Member
|
Clearly this is just created with AI without any real explanation for why the pragma is needed ("old libc implementation" doesn't tell me anything) or why only the ref is part of the hash here. I am closing this now. Feel free to try again without the help of AI. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added
std::hash<osmium::NodeRef>specialization (hashesref()only, matchingoperator==) and unit tests for hash equality, inequality, and use instd::unordered_set.include/osmium/osm/node_ref.hpp#include <functional>std::hash<osmium::NodeRef>specialization that hashes onlyref()— matching whatoperator==compares (ref-only). Follows the same pattern (clang pragma, argument_type/result_type) as the existingstd::hash<osmium::Location>in location.hpptest/t/osm/test_node_ref.cpp#include <functional>and#include <unordered_set>std::unordered_set