Skip to content

Make NodeRef hashable - #408

Closed
DennisOSRM wants to merge 1 commit into
osmcode:masterfrom
DennisOSRM:node_ref_hash
Closed

Make NodeRef hashable#408
DennisOSRM wants to merge 1 commit into
osmcode:masterfrom
DennisOSRM:node_ref_hash

Conversation

@DennisOSRM

@DennisOSRM DennisOSRM commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

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

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
Copilot AI lite review requested due to automatic review settings August 4, 2026 19:12
}

TEST_CASE("Equality comparison fo NodeRefs") {
TEST_CASE("Equality comparison of NodeRefs") {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix of an unrelated typo ;)

This comment was marked as spam.

@joto

joto commented Aug 4, 2026

Copy link
Copy Markdown
Member

Please don't invite AI slop into this repo.

@joto

joto commented Aug 4, 2026

Copy link
Copy Markdown
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.

@joto joto closed this Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants