From 746dddc0673d7261f19b1e056e90e6e3a49ef33a Mon Sep 17 00:00:00 2001 From: reduz Date: Fri, 13 May 2022 15:04:37 +0200 Subject: Replace most uses of Map by HashMap * Map is unnecessary and inefficient in almost every case. * Replaced by the new HashMap. * Renamed Map to RBMap and Set to RBSet for cases that still make sense (order matters) but use is discouraged. There were very few cases where replacing by HashMap was undesired because keeping the key order was intended. I tried to keep those (as RBMap) as much as possible, but might have missed some. Review appreciated! --- modules/navigation/nav_map.cpp | 4 ++-- modules/navigation/nav_map.h | 2 +- modules/navigation/nav_utils.h | 12 ++++++++---- 3 files changed, 11 insertions(+), 7 deletions(-) (limited to 'modules/navigation') diff --git a/modules/navigation/nav_map.cpp b/modules/navigation/nav_map.cpp index cbc0adc574..344475fb37 100644 --- a/modules/navigation/nav_map.cpp +++ b/modules/navigation/nav_map.cpp @@ -541,7 +541,7 @@ void NavMap::sync() { } // Group all edges per key. - Map> connections; + HashMap, gd::EdgeKey> connections; for (size_t poly_id(0); poly_id < polygons.size(); poly_id++) { gd::Polygon &poly(polygons[poly_id]); @@ -549,7 +549,7 @@ void NavMap::sync() { int next_point = (p + 1) % poly.points.size(); gd::EdgeKey ek(poly.points[p].key, poly.points[next_point].key); - Map>::Element *connection = connections.find(ek); + HashMap, gd::EdgeKey>::Iterator connection = connections.find(ek); if (!connection) { connections[ek] = Vector(); } diff --git a/modules/navigation/nav_map.h b/modules/navigation/nav_map.h index 5232e42bed..0ebdea30e1 100644 --- a/modules/navigation/nav_map.h +++ b/modules/navigation/nav_map.h @@ -34,7 +34,7 @@ #include "nav_rid.h" #include "core/math/math_defs.h" -#include "core/templates/map.h" +#include "core/templates/rb_map.h" #include "core/templates/thread_work_pool.h" #include "nav_utils.h" diff --git a/modules/navigation/nav_utils.h b/modules/navigation/nav_utils.h index 5b6c695ca4..a9f4e0e2fc 100644 --- a/modules/navigation/nav_utils.h +++ b/modules/navigation/nav_utils.h @@ -32,8 +32,9 @@ #define NAV_UTILS_H #include "core/math/vector3.h" +#include "core/templates/hash_map.h" +#include "core/templates/hashfuncs.h" #include "core/templates/vector.h" - #include class NavRegion; @@ -49,15 +50,18 @@ union PointKey { }; uint64_t key = 0; - bool operator<(const PointKey &p_key) const { return key < p_key.key; } }; struct EdgeKey { PointKey a; PointKey b; - bool operator<(const EdgeKey &p_key) const { - return (a.key == p_key.a.key) ? (b.key < p_key.b.key) : (a.key < p_key.a.key); + static uint32_t hash(const EdgeKey &p_val) { + return hash_one_uint64(p_val.a.key) ^ hash_one_uint64(p_val.b.key); + } + + bool operator==(const EdgeKey &p_key) const { + return (a.key == p_key.a.key) && (b.key == p_key.b.key); } EdgeKey(const PointKey &p_a = PointKey(), const PointKey &p_b = PointKey()) : -- cgit v1.2.3