Skip to content

Commit

Permalink
Specialize std::hash for NodeId/SubmapId
Browse files Browse the repository at this point in the history
Signed-off-by: Bosco Siu <[email protected]>
  • Loading branch information
boscosiu committed Nov 5, 2022
1 parent ef00de2 commit 09790ba
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions cartographer/mapping/id.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
#include <memory>
#include <ostream>
#include <tuple>
#include <utility>
#include <vector>

#include "absl/hash/hash.h"
#include "absl/memory/memory.h"
#include "cartographer/common/port.h"
#include "cartographer/common/time.h"
Expand Down Expand Up @@ -420,4 +422,21 @@ class MapById {
} // namespace mapping
} // namespace cartographer

template <>
struct std::hash<cartographer::mapping::NodeId> {
std::size_t operator()(
const cartographer::mapping::NodeId& id) const noexcept {
return absl::Hash<std::pair<int, int>>{}({id.trajectory_id, id.node_index});
}
};

template <>
struct std::hash<cartographer::mapping::SubmapId> {
std::size_t operator()(
const cartographer::mapping::SubmapId& id) const noexcept {
return absl::Hash<std::pair<int, int>>{}(
{id.trajectory_id, id.submap_index});
}
};

#endif // CARTOGRAPHER_MAPPING_ID_H_

0 comments on commit 09790ba

Please sign in to comment.