Skip to content

Commit bd9d6ee

Browse files
committed
Specialize std::hash for NodeId/SubmapId
Signed-off-by: Bosco Siu <opensource@qadyence.com>
1 parent ef00de2 commit bd9d6ee

File tree

1 file changed

+20
-0
lines changed
  • cartographer/mapping

1 file changed

+20
-0
lines changed

cartographer/mapping/id.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525
#include <memory>
2626
#include <ostream>
2727
#include <tuple>
28+
#include <utility>
2829
#include <vector>
2930

31+
#include "absl/hash/hash.h"
3032
#include "absl/memory/memory.h"
3133
#include "cartographer/common/port.h"
3234
#include "cartographer/common/time.h"
@@ -79,6 +81,11 @@ struct NodeId {
7981
}
8082
};
8183

84+
template <typename H>
85+
H AbslHashValue(H h, const NodeId& id) {
86+
return H::combine(std::move(h), id.trajectory_id, id.node_index);
87+
}
88+
8289
inline std::ostream& operator<<(std::ostream& os, const NodeId& v) {
8390
return os << "(" << v.trajectory_id << ", " << v.node_index << ")";
8491
}
@@ -110,6 +117,11 @@ struct SubmapId {
110117
}
111118
};
112119

120+
template <typename H>
121+
H AbslHashValue(H h, const SubmapId& id) {
122+
return H::combine(std::move(h), id.trajectory_id, id.submap_index);
123+
}
124+
113125
inline std::ostream& operator<<(std::ostream& os, const SubmapId& v) {
114126
return os << "(" << v.trajectory_id << ", " << v.submap_index << ")";
115127
}
@@ -420,4 +432,12 @@ class MapById {
420432
} // namespace mapping
421433
} // namespace cartographer
422434

435+
template <>
436+
struct std::hash<cartographer::mapping::NodeId>
437+
: absl::Hash<cartographer::mapping::NodeId> {};
438+
439+
template <>
440+
struct std::hash<cartographer::mapping::SubmapId>
441+
: absl::Hash<cartographer::mapping::SubmapId> {};
442+
423443
#endif // CARTOGRAPHER_MAPPING_ID_H_

0 commit comments

Comments
 (0)