Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ankerl::unordered_dense::map instead of std::unordered_map in UnorderedMapStorage #6922

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
178bcb9
Add ankerl
SiarheiFedartsou May 30, 2024
f1087e8
Squashed 'third_party/unordered_dense/' content from commit 231e48c94
SiarheiFedartsou May 30, 2024
fafe1d4
Merge commit 'f1087e81ecdca5a59ba5ffca684c955c5b38f7c2' as 'third_par…
SiarheiFedartsou May 30, 2024
0f5ffc2
Try to use ankerl::unordered_dense::map instead of std::unordered_map…
SiarheiFedartsou May 30, 2024
c368320
Try to use ankerl::unordered_dense::map instead of std::unordered_map…
SiarheiFedartsou May 30, 2024
cf4141d
Try to use ankerl::unordered_dense::map instead of std::unordered_map…
SiarheiFedartsou May 30, 2024
2e54842
Merge branch 'master' into sf-ankerl
SiarheiFedartsou Jun 5, 2024
2e3f3e9
Merge branch 'master' into sf-ankerl
SiarheiFedartsou Jun 8, 2024
9398bbc
wip
SiarheiFedartsou Jun 9, 2024
ada954c
wip
SiarheiFedartsou Jun 9, 2024
2a3f539
wip
SiarheiFedartsou Jun 9, 2024
67558b7
wip
SiarheiFedartsou Jun 9, 2024
c5cf8c3
Merge branch 'master' into sf-ankerl
SiarheiFedartsou Jun 9, 2024
79da379
wip
SiarheiFedartsou Jun 9, 2024
47d1630
wip
SiarheiFedartsou Jun 9, 2024
93820be
Avoid copy of intersection in totalTurnAngle
SiarheiFedartsou Jun 9, 2024
13d8eeb
wip
SiarheiFedartsou Jun 9, 2024
a65c9cb
wip
SiarheiFedartsou Jun 10, 2024
ff02ae9
wip
SiarheiFedartsou Jun 10, 2024
068a1da
wip
SiarheiFedartsou Jun 11, 2024
68d5dbc
wip
SiarheiFedartsou Jun 11, 2024
49f07cb
wip
SiarheiFedartsou Jun 11, 2024
f4ce1dc
wip
SiarheiFedartsou Jun 12, 2024
11c3369
wip
SiarheiFedartsou Jun 12, 2024
250c406
wip
SiarheiFedartsou Jun 12, 2024
112e089
wip
SiarheiFedartsou Jun 12, 2024
1724c3a
wip
SiarheiFedartsou Jun 12, 2024
316b8db
wip
SiarheiFedartsou Jun 12, 2024
559768c
wip
SiarheiFedartsou Jun 12, 2024
3ff2819
wip
SiarheiFedartsou Jun 13, 2024
72527d6
Merge branch 'master' into sf-ankerl
SiarheiFedartsou Jun 25, 2024
6f444be
ankerl
SiarheiFedartsou Jun 25, 2024
a522016
wip
SiarheiFedartsou Jun 26, 2024
8aade38
wip
SiarheiFedartsou Jun 26, 2024
8b878a8
Merge branch 'master' into sf-ankerl
SiarheiFedartsou Jun 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/osrm-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ jobs:
gunzip -c ./pr/test/data/poland_gps_traces.csv.gz > ~/gps_traces.csv
else
if [ ! -f "~/data.osm.pbf" ]; then
wget http://download.geofabrik.de/europe/germany/berlin-latest.osm.pbf -O ~/data.osm.pbf
wget http://download.geofabrik.de/europe/germany/berlin-latest.osm.pbf -O ~/data.osm.pbf --quiet
else
echo "Using cached data.osm.pbf"
fi
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ include_directories(SYSTEM ${PROTOZERO_INCLUDE_DIR})
set(VTZERO_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/vtzero/include")
include_directories(SYSTEM ${VTZERO_INCLUDE_DIR})

set(ANKERL_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/unordered_dense/include")
include_directories(SYSTEM ${ANKERL_INCLUDE_DIR})


set(FLATBUFFERS_BUILD_TESTS OFF CACHE BOOL "Disable the build of Flatbuffers tests and samples.")
set(FLATBUFFERS_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/flatbuffers")
set(FLATBUFFERS_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/flatbuffers/include")
Expand Down
72 changes: 5 additions & 67 deletions include/util/query_heap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,19 @@
#include <boost/heap/d_ary_heap.hpp>

#include <algorithm>
#include <ankerl/unordered_dense.h>
#include <boost/unordered_map.hpp>
#include <cstdint>
#include <limits>
#include <map>
#include <optional>
#include <unordered_map>
#include <unordered_set>
#include <vector>

namespace osrm::util
{

template <typename NodeID, typename Key> class GenerationArrayStorage
{
using GenerationCounter = std::uint16_t;

public:
explicit GenerationArrayStorage(std::size_t size)
: positions(size, 0), generation(1), generations(size, 0)
{
}

Key &operator[](NodeID node)
{
generation[node] = generation;
return positions[node];
}

Key peek_index(const NodeID node) const
{
if (generations[node] < generation)
{
return std::numeric_limits<Key>::max();
}
return positions[node];
}

void Clear()
{
generation++;
// if generation overflows we end up at 0 again and need to clear the vector
if (generation == 0)
{
generation = 1;
std::fill(generations.begin(), generations.end(), 0);
}
}

private:
GenerationCounter generation;
std::vector<GenerationCounter> generations;
std::vector<Key> positions;
};

template <typename NodeID, typename Key> class ArrayStorage
{
public:
Expand All @@ -72,33 +33,10 @@ template <typename NodeID, typename Key> class ArrayStorage
std::vector<Key> positions;
};

template <typename NodeID, typename Key> class MapStorage
{
public:
explicit MapStorage(std::size_t) {}

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

void Clear() { nodes.clear(); }

Key peek_index(const NodeID node) const
{
const auto iter = nodes.find(node);
if (nodes.end() != iter)
{
return iter->second;
}
return std::numeric_limits<Key>::max();
}

private:
std::map<NodeID, Key> nodes;
};

template <typename NodeID, typename Key> class UnorderedMapStorage
{
public:
explicit UnorderedMapStorage(std::size_t) { nodes.rehash(1000); }
explicit UnorderedMapStorage(std::size_t) {}

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

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

private:
std::unordered_map<NodeID, Key> nodes;
ankerl::unordered_dense::segmented_map<NodeID, Key> nodes;
};

template <typename NodeID,
Expand Down
2 changes: 1 addition & 1 deletion scripts/ci/post_benchmark_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@ def main():


if __name__ == "__main__":
main()
main()
5 changes: 4 additions & 1 deletion scripts/update_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ VTZERO_TAG=v1.1.0
FMT_PATH="fmtlib/fmt"
FMT_TAG=v10.2.1

ANKERL_PATH="martinus/unordered_dense"
ANKERL_TAG=v4.4.0

function update_subtree () {
name=$(echo "$1" | tr '[:lower:]' '[:upper:]')
path=$(tmpvar=${name}_PATH && echo ${!tmpvar})
Expand All @@ -53,6 +56,6 @@ function update_subtree () {
}

## Update dependencies
for dep in osmium sol rapidjson microtar protozero vtzero fmt; do
for dep in ankerl osmium sol rapidjson microtar protozero vtzero fmt; do
update_subtree $dep
done
20 changes: 20 additions & 0 deletions third_party/unordered_dense/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# see https://clang.llvm.org/docs/ClangFormatStyleOptions.html
---
BasedOnStyle: LLVM
Language: Cpp
Standard: c++17
ColumnLimit: 127

AccessModifierOffset: -4
AlignEscapedNewlines: Left
AllowShortFunctionsOnASingleLine: Empty
AllowShortLambdasOnASingleLine: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
BreakConstructorInitializers: BeforeComma
BreakStringLiterals: false
IndentPPDirectives: AfterHash
IndentWidth: 4
PointerAlignment: Left
UseTab: Never
55 changes: 55 additions & 0 deletions third_party/unordered_dense/.clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
Checks: '*
-abseil-string-find-str-contains
-altera*
-bugprone-easily-swappable-parameters
-cert-err58-cpp
-cppcoreguidelines-avoid-magic-numbers
-cppcoreguidelines-pro-bounds-constant-array-index
-cppcoreguidelines-pro-bounds-pointer-arithmetic
-fuchsia*
-llvm-header-guard
-llvmlibc*
-readability-function-cognitive-complexity
-readability-identifier-length
-readability-magic-numbers
'
HeaderFilterRegex: ''
CheckOptions:
cppcoreguidelines-avoid-do-while.IgnoreMacros: 'true'
readability-identifier-naming.MacroDefinitionCase: 'UPPER_CASE'
readability-identifier-naming.TemplateParameterCase: 'CamelCase'
readability-identifier-naming.TypeTemplateParameterCase: 'CamelCase'
readability-identifier-naming.ValueTemplateParameterCase: 'CamelCase'
readability-identifier-naming.ParameterPackCase: 'lower_case'
readability-identifier-naming.AbstractClassCase: 'lower_case'
readability-identifier-naming.ClassCase: 'lower_case'
readability-identifier-naming.ClassMemberCase: 'lower_case'
readability-identifier-naming.ConstantCase: 'lower_case'
readability-identifier-naming.ConstexprVariableCase: 'lower_case'
readability-identifier-naming.EnumCase: 'lower_case'
readability-identifier-naming.EnumConstantCase: 'lower_case'
readability-identifier-naming.FunctionCase: 'lower_case'
readability-identifier-naming.GlobalConstantCase: 'lower_case'
readability-identifier-naming.LocalVariableCase: 'lower_case'
readability-identifier-naming.MemberCase: 'lower_case'
readability-identifier-naming.NamespaceCase: 'lower_case'
readability-identifier-naming.ParameterCase: 'lower_case'
readability-identifier-naming.StructCase: 'lower_case'
readability-identifier-naming.TypeAliasCase: 'lower_case'
readability-identifier-naming.TypedefCase: 'lower_case'
readability-identifier-naming.StaticConstantCase: 'lower_case'
readability-identifier-naming.StaticVariableCase: 'lower_case'
readability-identifier-naming.UnionCase: 'lower_case'
readability-identifier-naming.VariableCase: 'lower_case'
readability-identifier-naming.GlobalConstantPrefix: 'global_'
readability-identifier-naming.GlobalVariablePrefix: 'global_'
readability-identifier-naming.MemberPrefix: 'm_'
readability-identifier-naming.PrivateMemberPrefix: 'm_'
readability-identifier-naming.PrivateMemberPrefix: 'm_'
readability-identifier-naming.ProtectedMemberPrefix: 'm_'
readability-identifier-naming.PublicMemberPrefix: ''
readability-identifier-naming.StaticConstantPrefix: 'static_'
readability-identifier-naming.StaticVariablePrefix: 'static_'
readability-identifier-naming.ClassMemberPrefix: 'static_'
...
1 change: 1 addition & 0 deletions third_party/unordered_dense/.fuzz-corpus-base-dir
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data/fuzz
13 changes: 13 additions & 0 deletions third_party/unordered_dense/.github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# These are supported funding model platforms

github: [martinus] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
28 changes: 28 additions & 0 deletions third_party/unordered_dense/.github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
name: Bug report
about: Create a report to help us improve
title: "[BUG] "
labels: bug
assignees: martinus

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1.
2.
3.

**Expected behavior**
A clear and concise description of what you expected to happen.

**System (please complete the following information):**
- OS: [e.g. Linux]
- Compiler: [e.g. clang++, g++]
- Version [e.g. 13.0.1]

**Additional context**
Add any other context about the problem here.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: martinus

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
74 changes: 74 additions & 0 deletions third_party/unordered_dense/.github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Build, Test, Lint

on: [push, pull_request]

# see https://github.com/mesonbuild/meson/blob/master/docs/markdown/Continuous-Integration.md
jobs:

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.x'
- run: ./scripts/lint/lint-version.py

linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: sudo apt-get install -yq libboost-dev
- uses: hendrikmuhs/[email protected]
- uses: actions/setup-python@v4
with:
python-version: '3.x'
- run: pip install meson ninja
- run: meson setup builddir/
env:
CXX: ccache c++
- run: meson test -C builddir/ -v
- uses: actions/upload-artifact@v3
if: failure()
with:
name: Linux_Meson_Testlog
path: builddir/meson-logs/testlog.txt

macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.x'
- run: brew install gcc ccache meson ninja
- run: meson setup builddir/
env:
CXX: ccache c++
- run: meson test -C builddir/ -v
- uses: actions/upload-artifact@v3
if: failure()
with:
name: MacOS_Meson_Testlog
path: builddir/meson-logs/testlog.txt

windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.x'
- uses: BSFishy/pip-action@v1
with:
packages: ninja meson
- uses: ilammy/msvc-dev-cmd@v1
- run: meson setup builddir
- run: meson test -C builddir -v
- uses: actions/upload-artifact@v3
if: failure()
with:
name: Windows_Meson_Testlog
path: |
builddir/meson-logs/testlog.txt
builddir/test/udm-test.exe
14 changes: 14 additions & 0 deletions third_party/unordered_dense/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
build
builddir
.cache
.vscode
compile_commands.json

# ignore all in subprojects except the .wrap files
/subprojects/*
!/subprojects/*.wrap

# c++ modules
*.pcm
a.out
*.o
Loading