Skip to content

Commit 7dcd641

Browse files
committed
Allow building OSRM with 64-bit IDs so we can extract planet.osm.pbf using foot profile
1 parent 08ed8ec commit 7dcd641

40 files changed

+208
-127
lines changed

CMakeLists.txt

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ option(ENABLE_LTO "Use LTO if available" OFF)
3535
option(ENABLE_FUZZING "Fuzz testing using LLVM's libFuzzer" OFF)
3636
option(ENABLE_NODE_BINDINGS "Build NodeJs bindings" OFF)
3737
option(ENABLE_CLANG_TIDY "Enables clang-tidy checks" OFF)
38+
option(USE_64BIT_IDS "Whether to use 64-bit node and edge IDs" OFF)
3839

3940
if (ENABLE_CLANG_TIDY)
4041
find_program(CLANG_TIDY_COMMAND NAMES clang-tidy)
@@ -89,6 +90,13 @@ else()
8990
add_definitions(-DOSRM_PROJECT_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
9091
endif()
9192

93+
if(USE_64BIT_IDS)
94+
add_definitions(-DUSE_64BIT_IDS)
95+
message(STATUS "Using 64-bit node and edge IDs")
96+
else()
97+
message(STATUS "Using 32-bit node and edge IDs")
98+
endif()
99+
92100
# these two functions build up custom variables:
93101
# DEPENDENCIES_INCLUDE_DIRS and OSRM_DEFINES
94102
# These variables we want to pass to
@@ -151,7 +159,7 @@ add_library(UPDATER OBJECT ${UpdaterGlob})
151159
add_library(STORAGE OBJECT ${StorageGlob})
152160
add_library(ENGINE OBJECT ${EngineGlob})
153161

154-
if (BUILD_ROUTED)
162+
if (BUILD_ROUTED)
155163
add_library(SERVER OBJECT ${ServerGlob})
156164
add_executable(osrm-routed src/tools/routed.cpp $<TARGET_OBJECTS:SERVER> $<TARGET_OBJECTS:UTIL>)
157165
endif()
@@ -309,7 +317,7 @@ add_subdirectory(${FLATBUFFERS_SRC_DIR}
309317
set(FMT_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/fmt-9.1.0/include")
310318
add_compile_definitions(FMT_HEADER_ONLY)
311319
include_directories(SYSTEM ${FMT_INCLUDE_DIR})
312-
320+
313321

314322
# see https://stackoverflow.com/questions/70898030/boost-link-error-using-conan-find-package
315323
if (MSVC)
@@ -319,7 +327,7 @@ endif()
319327
if(ENABLE_CONAN)
320328
message(STATUS "Installing dependencies via Conan")
321329

322-
# Conan will generate Find*.cmake files to build directory, so we use them with the highest priority
330+
# Conan will generate Find*.cmake files to build directory, so we use them with the highest priority
323331
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_BINARY_DIR})
324332
list(INSERT CMAKE_PREFIX_PATH 0 ${CMAKE_BINARY_DIR})
325333

@@ -330,26 +338,26 @@ if(ENABLE_CONAN)
330338
set(CONAN_EXPAT_VERSION "2.2.10#916908d4a570ad839edd25322c3268cd")
331339
set(CONAN_LUA_VERSION "5.4.4#3ec62efc37cd0a5d80b9e5cb35277360")
332340
set(CONAN_TBB_VERSION "2021.3.0#507ec17cbd51a84167e143b20d170eea")
333-
341+
334342
set(CONAN_SYSTEM_INCLUDES ON)
335343

336-
# TODO:
337-
# if we link TBB dynamically osrm-extract.exe finishes on the first access to any TBB symbol
344+
# TODO:
345+
# if we link TBB dynamically osrm-extract.exe finishes on the first access to any TBB symbol
338346
# with exit code = -1073741515, which means that program cannot load required DLL.
339347
if (MSVC)
340348
set(TBB_SHARED False)
341349
else()
342350
set(TBB_SHARED True)
343351
endif()
344352

345-
set(CONAN_ARGS
346-
REQUIRES
353+
set(CONAN_ARGS
354+
REQUIRES
347355
"boost/${CONAN_BOOST_VERSION}"
348356
"bzip2/${CONAN_BZIP2_VERSION}"
349357
"expat/${CONAN_EXPAT_VERSION}"
350358
"lua/${CONAN_LUA_VERSION}"
351359
"onetbb/${CONAN_TBB_VERSION}"
352-
BASIC_SETUP
360+
BASIC_SETUP
353361
GENERATORS cmake_find_package json # json generator generates a conanbuildinfo.json in the build folder so (non-CMake) projects can easily parse OSRM's dependencies
354362
KEEP_RPATHS
355363
NO_OUTPUT_DIRS
@@ -386,7 +394,7 @@ if(ENABLE_CONAN)
386394
set(Boost_ZLIB_LIBRARY "${Boost_zlib_LIB_TARGETS}")
387395
set(Boost_REGEX_LIBRARY "${Boost_regex_LIB_TARGETS}")
388396
set(Boost_UNIT_TEST_FRAMEWORK_LIBRARY "${Boost_unit_test_framework_LIB_TARGETS}")
389-
397+
390398

391399
find_package(BZip2 REQUIRED)
392400
find_package(EXPAT REQUIRED)
@@ -730,23 +738,23 @@ if (ENABLE_FUZZING)
730738
add_subdirectory(fuzz)
731739
endif ()
732740

733-
# add headers sanity check target that includes all headers independently
734-
set(check_headers_dir "${PROJECT_BINARY_DIR}/check-headers")
735-
file(GLOB_RECURSE headers_to_check
736-
${PROJECT_BINARY_DIR}/*.hpp
737-
${PROJECT_SOURCE_DIR}/include/*.hpp)
738-
foreach(header ${headers_to_check})
741+
# add headers sanity check target that includes all headers independently
742+
set(check_headers_dir "${PROJECT_BINARY_DIR}/check-headers")
743+
file(GLOB_RECURSE headers_to_check
744+
${PROJECT_BINARY_DIR}/*.hpp
745+
${PROJECT_SOURCE_DIR}/include/*.hpp)
746+
foreach(header ${headers_to_check})
739747
if ("${header}" MATCHES ".*/include/nodejs/.*")
740748
# we do not check NodeJS bindings headers
741749
continue()
742750
endif()
743-
get_filename_component(filename ${header} NAME_WE)
744-
set(filename "${check_headers_dir}/${filename}.cpp")
745-
if (NOT EXISTS ${filename})
746-
file(WRITE ${filename} "#include \"${header}\"\n")
747-
endif()
748-
list(APPEND sources ${filename})
749-
endforeach()
750-
add_library(check-headers STATIC EXCLUDE_FROM_ALL ${sources})
751-
set_target_properties(check-headers PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${check_headers_dir})
751+
get_filename_component(filename ${header} NAME_WE)
752+
set(filename "${check_headers_dir}/${filename}.cpp")
753+
if (NOT EXISTS ${filename})
754+
file(WRITE ${filename} "#include \"${header}\"\n")
755+
endif()
756+
list(APPEND sources ${filename})
757+
endforeach()
758+
add_library(check-headers STATIC EXCLUDE_FROM_ALL ${sources})
759+
set_target_properties(check-headers PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${check_headers_dir})
752760

include/contractor/graph_contractor_adaptors.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ template <class Edge, typename GraphT> inline std::vector<Edge> toEdges(GraphT g
145145
util::Percent p(log, graph.GetNumberOfNodes());
146146
const NodeID number_of_nodes = graph.GetNumberOfNodes();
147147
std::size_t edge_index = 0;
148-
for (const auto node : util::irange(0u, number_of_nodes))
148+
for (const auto node : util::irange(MIN_NODEID, number_of_nodes))
149149
{
150150
p.PrintStatus(node);
151151
for (auto edge : graph.GetAdjacentEdgeRange(node))

include/contractor/query_edge.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ struct QueryEdge
4545
// this ID is either the middle node of the shortcut, or the ID of the edge based node (node
4646
// based edge) storing the appropriate data. If `shortcut` is set to true, we get the middle
4747
// node. Otherwise we see the edge based node to access node data.
48+
#ifdef USE_64BIT_IDS
49+
NodeID turn_id : 63;
50+
#else
4851
NodeID turn_id : 31;
52+
#endif
4953
bool shortcut : 1;
5054
EdgeWeight weight;
5155
EdgeDuration::value_type duration : 30;

include/engine/datafacade/algorithm_datafacade.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ template <> class AlgorithmDataFacade<CH>
3030
virtual ~AlgorithmDataFacade() = default;
3131

3232
// search graph access
33-
virtual unsigned GetNumberOfNodes() const = 0;
33+
virtual NodeID GetNumberOfNodes() const = 0;
3434

35-
virtual unsigned GetNumberOfEdges() const = 0;
35+
virtual EdgeID GetNumberOfEdges() const = 0;
3636

3737
virtual unsigned GetOutDegree(const NodeID edge_based_node_id) const = 0;
3838

@@ -67,11 +67,11 @@ template <> class AlgorithmDataFacade<MLD>
6767
virtual ~AlgorithmDataFacade() = default;
6868

6969
// search graph access
70-
virtual unsigned GetNumberOfNodes() const = 0;
70+
virtual NodeID GetNumberOfNodes() const = 0;
7171

72-
virtual unsigned GetMaxBorderNodeID() const = 0;
72+
virtual NodeID GetMaxBorderNodeID() const = 0;
7373

74-
virtual unsigned GetNumberOfEdges() const = 0;
74+
virtual EdgeID GetNumberOfEdges() const = 0;
7575

7676
virtual unsigned GetOutDegree(const NodeID edge_based_node_id) const = 0;
7777

include/engine/datafacade/contiguous_internalmem_datafacade.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ class ContiguousInternalMemoryAlgorithmDataFacade<CH> : public datafacade::Algor
6565
}
6666

6767
// search graph access
68-
unsigned GetNumberOfNodes() const override final { return m_query_graph.GetNumberOfNodes(); }
68+
NodeID GetNumberOfNodes() const override final { return m_query_graph.GetNumberOfNodes(); }
6969

70-
unsigned GetNumberOfEdges() const override final { return m_query_graph.GetNumberOfEdges(); }
70+
EdgeID GetNumberOfEdges() const override final { return m_query_graph.GetNumberOfEdges(); }
7171

7272
unsigned GetOutDegree(const NodeID edge_based_node_id) const override final
7373
{
@@ -609,11 +609,11 @@ template <> class ContiguousInternalMemoryAlgorithmDataFacade<MLD> : public Algo
609609
const customizer::CellMetricView &GetCellMetric() const override { return mld_cell_metric; }
610610

611611
// search graph access
612-
unsigned GetNumberOfNodes() const override final { return query_graph.GetNumberOfNodes(); }
612+
NodeID GetNumberOfNodes() const override final { return query_graph.GetNumberOfNodes(); }
613613

614-
unsigned GetMaxBorderNodeID() const override final { return query_graph.GetMaxBorderNodeID(); }
614+
NodeID GetMaxBorderNodeID() const override final { return query_graph.GetMaxBorderNodeID(); }
615615

616-
unsigned GetNumberOfEdges() const override final { return query_graph.GetNumberOfEdges(); }
616+
EdgeID GetNumberOfEdges() const override final { return query_graph.GetNumberOfEdges(); }
617617

618618
unsigned GetOutDegree(const NodeID edge_based_node_id) const override final
619619
{

include/engine/guidance/assemble_leg.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct NamedSegment
3232
{
3333
EdgeDuration duration;
3434
std::uint32_t position;
35-
std::uint32_t name_id;
35+
NameID name_id;
3636
};
3737

3838
template <std::size_t SegmentNumber>

include/engine/guidance/route_step.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ inline IntermediateIntersection getInvalidIntersection()
5656
struct RouteStep
5757
{
5858
NodeID from_id;
59-
unsigned name_id;
59+
NameID name_id;
6060
bool is_segregated;
6161
std::string name;
6262
std::string ref;

include/engine/hint.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,16 @@ struct Hint
7676
static Hint FromBase64(const std::string &base64Hint);
7777
};
7878

79+
#ifdef USE_64BIT_IDS
80+
static_assert(sizeof(SegmentHint) == 96 + 8, "Hint is bigger than expected");
81+
// 140 == ceil(104 / 3) * 4 since we use integer division
82+
constexpr std::size_t ENCODED_SEGMENT_HINT_SIZE = 140;
83+
#else
7984
static_assert(sizeof(SegmentHint) == 80 + 4, "Hint is bigger than expected");
8085
constexpr std::size_t ENCODED_SEGMENT_HINT_SIZE = 112;
86+
#endif
8187
static_assert(ENCODED_SEGMENT_HINT_SIZE / 4 * 3 >= sizeof(SegmentHint),
8288
"ENCODED_SEGMENT_HINT_SIZE does not match size of SegmentHint");
83-
8489
} // namespace osrm::engine
8590

8691
#endif

include/engine/phantom_node.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,11 @@ struct PhantomNode
222222
unsigned short bearing : 12;
223223
};
224224

225+
#ifdef USE_64BIT_IDS
226+
static_assert(sizeof(PhantomNode) == 96, "PhantomNode has more padding then expected");
227+
#else
225228
static_assert(sizeof(PhantomNode) == 80, "PhantomNode has more padding then expected");
229+
#if
226230

227231
using PhantomNodeCandidates = std::vector<PhantomNode>;
228232
using PhantomCandidateAlternatives = std::pair<PhantomNodeCandidates, PhantomNodeCandidates>;

include/extractor/compressed_edge_container.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class CompressedEdgeContainer
4646
const EdgeDuration duration);
4747

4848
void InitializeBothwayVector();
49-
unsigned ZipEdges(const unsigned f_edge_pos, const unsigned r_edge_pos);
49+
unsigned ZipEdges(const EdgeID f_edge_pos, const EdgeID r_edge_pos);
5050

5151
bool HasEntryForID(const EdgeID edge_id) const;
5252
bool HasZippedEntryForForwardID(const EdgeID edge_id) const;

0 commit comments

Comments
 (0)