From 058b8c3b315b020d52cb877afd5c24b58d942dba Mon Sep 17 00:00:00 2001 From: Lauren Budorick Date: Fri, 27 May 2016 13:30:30 -0400 Subject: [PATCH] Template vector --- .../engine/datafacade/internal_datafacade.hpp | 2 +- .../engine/datafacade/shared_datafacade.hpp | 2 +- include/util/packed_vector.hpp | 19 ++++++++++--------- src/storage/storage.cpp | 2 +- unit_tests/util/packed_vector.cpp | 4 ++-- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/include/engine/datafacade/internal_datafacade.hpp b/include/engine/datafacade/internal_datafacade.hpp index 38af1d607..a5732b817 100644 --- a/include/engine/datafacade/internal_datafacade.hpp +++ b/include/engine/datafacade/internal_datafacade.hpp @@ -74,7 +74,7 @@ class InternalDataFacade final : public BaseDataFacade std::string m_timestamp; util::ShM::vector m_coordinate_list; - util::PackedVector m_osmnodeid_list; + util::PackedVector m_osmnodeid_list; util::ShM::vector m_via_node_list; util::ShM::vector m_name_ID_list; util::ShM::vector m_turn_instruction_list; diff --git a/include/engine/datafacade/shared_datafacade.hpp b/include/engine/datafacade/shared_datafacade.hpp index 7e22f0b4f..cf607fc83 100644 --- a/include/engine/datafacade/shared_datafacade.hpp +++ b/include/engine/datafacade/shared_datafacade.hpp @@ -76,7 +76,7 @@ class SharedDataFacade final : public BaseDataFacade extractor::ProfileProperties *m_profile_properties; util::ShM::vector m_coordinate_list; - util::PackedVector m_osmnodeid_list; + util::PackedVector m_osmnodeid_list; util::ShM::vector m_via_node_list; util::ShM::vector m_name_ID_list; util::ShM::vector m_turn_instruction_list; diff --git a/include/util/packed_vector.hpp b/include/util/packed_vector.hpp index 70dc82945..3083d4314 100644 --- a/include/util/packed_vector.hpp +++ b/include/util/packed_vector.hpp @@ -37,13 +37,14 @@ inline std::size_t PackedVectorCapacity(std::size_t vec_size) * Since OSM node IDs are (at the time of writing) not quite yet overflowing 32 bits, and * will predictably be containable within 33 bits for a long time, the following packs * 64-bit OSM IDs as 33-bit numbers within a 64-bit vector. + * + * NOTE: this type is templated for future use, but will require a slight refactor to + * configure BITSIZE and ELEMSIZE */ -template class PackedVector +template class PackedVector { public: - PackedVector() = default; - - void push_back(OSMNodeID incoming_node_id) + void push_back(T incoming_node_id) { std::uint64_t node_id = static_cast(incoming_node_id); @@ -83,7 +84,7 @@ template class PackedVector num_elements++; } - OSMNodeID at(const std::size_t &a_index) const + T at(const std::size_t &a_index) const { BOOST_ASSERT(a_index < num_elements); @@ -101,14 +102,14 @@ template class PackedVector if (left_index == 0) { // ID is at the far left side of this element - return static_cast(elem >> (ELEMSIZE - BITSIZE)); + return static_cast(elem >> (ELEMSIZE - BITSIZE)); } else if (left_index >= BITSIZE) { // ID is entirely contained within this element const std::uint64_t at_right = elem >> (left_index - BITSIZE); const std::uint64_t left_mask = static_cast(pow(2, BITSIZE)) - 1; - return static_cast(at_right & left_mask); + return static_cast(at_right & left_mask); } else { @@ -120,7 +121,7 @@ template class PackedVector const std::uint64_t next_elem = static_cast(vec.at(index + 1)); const std::uint64_t right_side = next_elem >> (ELEMSIZE - (BITSIZE - left_index)); - return static_cast(left_side | right_side); + return static_cast(left_side | right_side); } } @@ -133,7 +134,7 @@ template class PackedVector } template - void reset(typename std::enable_if::type *ptr, + void reset(typename std::enable_if::type *ptr, typename std::enable_if::type size) { vec.reset(reinterpret_cast(ptr), size); diff --git a/src/storage/storage.cpp b/src/storage/storage.cpp index 93055af46..9144bfb2f 100644 --- a/src/storage/storage.cpp +++ b/src/storage/storage.cpp @@ -542,7 +542,7 @@ int Storage::Run() shared_memory_ptr, SharedDataLayout::COORDINATE_LIST); OSMNodeID *osmnodeid_ptr = shared_layout_ptr->GetBlockPtr( shared_memory_ptr, SharedDataLayout::OSM_NODE_ID_LIST); - util::PackedVector osmnodeid_list; + util::PackedVector osmnodeid_list; osmnodeid_list.reset( osmnodeid_ptr, shared_layout_ptr->num_entries[storage::SharedDataLayout::OSM_NODE_ID_LIST]); diff --git a/unit_tests/util/packed_vector.cpp b/unit_tests/util/packed_vector.cpp index 6b69add91..46c65204f 100644 --- a/unit_tests/util/packed_vector.cpp +++ b/unit_tests/util/packed_vector.cpp @@ -12,7 +12,7 @@ using namespace osrm::util; // Verify that the packed vector behaves as expected BOOST_AUTO_TEST_CASE(insert_and_retrieve_packed_test) { - PackedVector packed_ids; + PackedVector packed_ids; std::vector original_ids; const constexpr std::size_t num_test_cases = 399; @@ -33,7 +33,7 @@ BOOST_AUTO_TEST_CASE(insert_and_retrieve_packed_test) BOOST_AUTO_TEST_CASE(packed_vector_capacity_test) { - PackedVector packed_vec; + PackedVector packed_vec; const std::size_t original_size = packed_vec.capacity(); std::vector dummy_vec;