From bd9d6ee4e2319c2060d3ec377e433b9ebce71f16 Mon Sep 17 00:00:00 2001 From: boscosiu Date: Mon, 31 Oct 2022 09:50:54 -0700 Subject: [PATCH] Specialize std::hash for NodeId/SubmapId Signed-off-by: Bosco Siu --- cartographer/mapping/id.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/cartographer/mapping/id.h b/cartographer/mapping/id.h index c5abdf9af7..f90a2c062e 100644 --- a/cartographer/mapping/id.h +++ b/cartographer/mapping/id.h @@ -25,8 +25,10 @@ #include #include #include +#include #include +#include "absl/hash/hash.h" #include "absl/memory/memory.h" #include "cartographer/common/port.h" #include "cartographer/common/time.h" @@ -79,6 +81,11 @@ struct NodeId { } }; +template +H AbslHashValue(H h, const NodeId& id) { + return H::combine(std::move(h), id.trajectory_id, id.node_index); +} + inline std::ostream& operator<<(std::ostream& os, const NodeId& v) { return os << "(" << v.trajectory_id << ", " << v.node_index << ")"; } @@ -110,6 +117,11 @@ struct SubmapId { } }; +template +H AbslHashValue(H h, const SubmapId& id) { + return H::combine(std::move(h), id.trajectory_id, id.submap_index); +} + inline std::ostream& operator<<(std::ostream& os, const SubmapId& v) { return os << "(" << v.trajectory_id << ", " << v.submap_index << ")"; } @@ -420,4 +432,12 @@ class MapById { } // namespace mapping } // namespace cartographer +template <> +struct std::hash + : absl::Hash {}; + +template <> +struct std::hash + : absl::Hash {}; + #endif // CARTOGRAPHER_MAPPING_ID_H_