Skip to content

Commit 09790ba

Browse files
committed
Specialize std::hash for NodeId/SubmapId
Signed-off-by: Bosco Siu <[email protected]>
1 parent ef00de2 commit 09790ba

File tree

1 file changed

+19
-0
lines changed
  • cartographer/mapping

1 file changed

+19
-0
lines changed

cartographer/mapping/id.h

+19
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"
@@ -420,4 +422,21 @@ class MapById {
420422
} // namespace mapping
421423
} // namespace cartographer
422424

425+
template <>
426+
struct std::hash<cartographer::mapping::NodeId> {
427+
std::size_t operator()(
428+
const cartographer::mapping::NodeId& id) const noexcept {
429+
return absl::Hash<std::pair<int, int>>{}({id.trajectory_id, id.node_index});
430+
}
431+
};
432+
433+
template <>
434+
struct std::hash<cartographer::mapping::SubmapId> {
435+
std::size_t operator()(
436+
const cartographer::mapping::SubmapId& id) const noexcept {
437+
return absl::Hash<std::pair<int, int>>{}(
438+
{id.trajectory_id, id.submap_index});
439+
}
440+
};
441+
423442
#endif // CARTOGRAPHER_MAPPING_ID_H_

0 commit comments

Comments
 (0)