Skip to content

Commit 0f5ffc2

Browse files
Try to use ankerl::unordered_dense::map instead of std::unordered_map in UnorderedMapStorage
1 parent fafe1d4 commit 0f5ffc2

File tree

2 files changed

+10
-46
lines changed

2 files changed

+10
-46
lines changed

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ include_directories(SYSTEM ${PROTOZERO_INCLUDE_DIR})
300300
set(VTZERO_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/vtzero/include")
301301
include_directories(SYSTEM ${VTZERO_INCLUDE_DIR})
302302

303+
set(ANKERL_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/unordered_dense/include")
304+
include_directories(SYSTEM ${ANKERL_INCLUDE_DIR})
305+
306+
303307
set(FLATBUFFERS_BUILD_TESTS OFF CACHE BOOL "Disable the build of Flatbuffers tests and samples.")
304308
set(FLATBUFFERS_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/flatbuffers")
305309
set(FLATBUFFERS_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/flatbuffers/include")
@@ -358,7 +362,7 @@ if(ENABLE_CONAN)
358362
KEEP_RPATHS
359363
NO_OUTPUT_DIRS
360364
OPTIONS boost:filesystem_version=3 # https://stackoverflow.com/questions/73392648/error-with-boost-filesystem-version-in-cmake
361-
onetbb:shared=${TBB_SHARED}
365+
# onetbb:shared=${TBB_SHARED}
362366
boost:without_stacktrace=True # Apple Silicon cross-compilation fails without it
363367
BUILD missing
364368
)

include/util/query_heap.hpp

Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,54 +9,12 @@
99
#include <limits>
1010
#include <map>
1111
#include <optional>
12-
#include <unordered_map>
12+
#include <ankerl/unordered_dense.h>
1313
#include <vector>
1414

1515
namespace osrm::util
1616
{
1717

18-
template <typename NodeID, typename Key> class GenerationArrayStorage
19-
{
20-
using GenerationCounter = std::uint16_t;
21-
22-
public:
23-
explicit GenerationArrayStorage(std::size_t size)
24-
: positions(size, 0), generation(1), generations(size, 0)
25-
{
26-
}
27-
28-
Key &operator[](NodeID node)
29-
{
30-
generation[node] = generation;
31-
return positions[node];
32-
}
33-
34-
Key peek_index(const NodeID node) const
35-
{
36-
if (generations[node] < generation)
37-
{
38-
return std::numeric_limits<Key>::max();
39-
}
40-
return positions[node];
41-
}
42-
43-
void Clear()
44-
{
45-
generation++;
46-
// if generation overflows we end up at 0 again and need to clear the vector
47-
if (generation == 0)
48-
{
49-
generation = 1;
50-
std::fill(generations.begin(), generations.end(), 0);
51-
}
52-
}
53-
54-
private:
55-
GenerationCounter generation;
56-
std::vector<GenerationCounter> generations;
57-
std::vector<Key> positions;
58-
};
59-
6018
template <typename NodeID, typename Key> class ArrayStorage
6119
{
6220
public:
@@ -98,7 +56,9 @@ template <typename NodeID, typename Key> class MapStorage
9856
template <typename NodeID, typename Key> class UnorderedMapStorage
9957
{
10058
public:
101-
explicit UnorderedMapStorage(std::size_t) { nodes.rehash(1000); }
59+
explicit UnorderedMapStorage(std::size_t) {
60+
nodes.rehash(1000);
61+
}
10262

10363
Key &operator[](const NodeID node) { return nodes[node]; }
10464

@@ -121,7 +81,7 @@ template <typename NodeID, typename Key> class UnorderedMapStorage
12181
void Clear() { nodes.clear(); }
12282

12383
private:
124-
std::unordered_map<NodeID, Key> nodes;
84+
ankerl::unordered_dense::map<NodeID, Key> nodes;
12585
};
12686

12787
template <typename NodeID,

0 commit comments

Comments
 (0)