Template vector
This commit is contained in:
parent
ae3ccb009e
commit
058b8c3b31
@ -74,7 +74,7 @@ class InternalDataFacade final : public BaseDataFacade
|
|||||||
std::string m_timestamp;
|
std::string m_timestamp;
|
||||||
|
|
||||||
util::ShM<util::Coordinate, false>::vector m_coordinate_list;
|
util::ShM<util::Coordinate, false>::vector m_coordinate_list;
|
||||||
util::PackedVector<false> m_osmnodeid_list;
|
util::PackedVector<OSMNodeID, false> m_osmnodeid_list;
|
||||||
util::ShM<NodeID, false>::vector m_via_node_list;
|
util::ShM<NodeID, false>::vector m_via_node_list;
|
||||||
util::ShM<unsigned, false>::vector m_name_ID_list;
|
util::ShM<unsigned, false>::vector m_name_ID_list;
|
||||||
util::ShM<extractor::guidance::TurnInstruction, false>::vector m_turn_instruction_list;
|
util::ShM<extractor::guidance::TurnInstruction, false>::vector m_turn_instruction_list;
|
||||||
|
@ -76,7 +76,7 @@ class SharedDataFacade final : public BaseDataFacade
|
|||||||
extractor::ProfileProperties *m_profile_properties;
|
extractor::ProfileProperties *m_profile_properties;
|
||||||
|
|
||||||
util::ShM<util::Coordinate, true>::vector m_coordinate_list;
|
util::ShM<util::Coordinate, true>::vector m_coordinate_list;
|
||||||
util::PackedVector<true> m_osmnodeid_list;
|
util::PackedVector<OSMNodeID, true> m_osmnodeid_list;
|
||||||
util::ShM<NodeID, true>::vector m_via_node_list;
|
util::ShM<NodeID, true>::vector m_via_node_list;
|
||||||
util::ShM<unsigned, true>::vector m_name_ID_list;
|
util::ShM<unsigned, true>::vector m_name_ID_list;
|
||||||
util::ShM<extractor::guidance::TurnInstruction, true>::vector m_turn_instruction_list;
|
util::ShM<extractor::guidance::TurnInstruction, true>::vector m_turn_instruction_list;
|
||||||
|
@ -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
|
* 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
|
* 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.
|
* 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 <bool UseSharedMemory> class PackedVector
|
template <typename T, bool UseSharedMemory> class PackedVector
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PackedVector() = default;
|
void push_back(T incoming_node_id)
|
||||||
|
|
||||||
void push_back(OSMNodeID incoming_node_id)
|
|
||||||
{
|
{
|
||||||
std::uint64_t node_id = static_cast<std::uint64_t>(incoming_node_id);
|
std::uint64_t node_id = static_cast<std::uint64_t>(incoming_node_id);
|
||||||
|
|
||||||
@ -83,7 +84,7 @@ template <bool UseSharedMemory> class PackedVector
|
|||||||
num_elements++;
|
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);
|
BOOST_ASSERT(a_index < num_elements);
|
||||||
|
|
||||||
@ -101,14 +102,14 @@ template <bool UseSharedMemory> class PackedVector
|
|||||||
if (left_index == 0)
|
if (left_index == 0)
|
||||||
{
|
{
|
||||||
// ID is at the far left side of this element
|
// ID is at the far left side of this element
|
||||||
return static_cast<OSMNodeID>(elem >> (ELEMSIZE - BITSIZE));
|
return static_cast<T>(elem >> (ELEMSIZE - BITSIZE));
|
||||||
}
|
}
|
||||||
else if (left_index >= BITSIZE)
|
else if (left_index >= BITSIZE)
|
||||||
{
|
{
|
||||||
// ID is entirely contained within this element
|
// ID is entirely contained within this element
|
||||||
const std::uint64_t at_right = elem >> (left_index - BITSIZE);
|
const std::uint64_t at_right = elem >> (left_index - BITSIZE);
|
||||||
const std::uint64_t left_mask = static_cast<std::uint64_t>(pow(2, BITSIZE)) - 1;
|
const std::uint64_t left_mask = static_cast<std::uint64_t>(pow(2, BITSIZE)) - 1;
|
||||||
return static_cast<OSMNodeID>(at_right & left_mask);
|
return static_cast<T>(at_right & left_mask);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -120,7 +121,7 @@ template <bool UseSharedMemory> class PackedVector
|
|||||||
const std::uint64_t next_elem = static_cast<std::uint64_t>(vec.at(index + 1));
|
const std::uint64_t next_elem = static_cast<std::uint64_t>(vec.at(index + 1));
|
||||||
|
|
||||||
const std::uint64_t right_side = next_elem >> (ELEMSIZE - (BITSIZE - left_index));
|
const std::uint64_t right_side = next_elem >> (ELEMSIZE - (BITSIZE - left_index));
|
||||||
return static_cast<OSMNodeID>(left_side | right_side);
|
return static_cast<T>(left_side | right_side);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +134,7 @@ template <bool UseSharedMemory> class PackedVector
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <bool enabled = UseSharedMemory>
|
template <bool enabled = UseSharedMemory>
|
||||||
void reset(typename std::enable_if<enabled, OSMNodeID>::type *ptr,
|
void reset(typename std::enable_if<enabled, T>::type *ptr,
|
||||||
typename std::enable_if<enabled, std::size_t>::type size)
|
typename std::enable_if<enabled, std::size_t>::type size)
|
||||||
{
|
{
|
||||||
vec.reset(reinterpret_cast<std::uint64_t *>(ptr), size);
|
vec.reset(reinterpret_cast<std::uint64_t *>(ptr), size);
|
||||||
|
@ -542,7 +542,7 @@ int Storage::Run()
|
|||||||
shared_memory_ptr, SharedDataLayout::COORDINATE_LIST);
|
shared_memory_ptr, SharedDataLayout::COORDINATE_LIST);
|
||||||
OSMNodeID *osmnodeid_ptr = shared_layout_ptr->GetBlockPtr<OSMNodeID, true>(
|
OSMNodeID *osmnodeid_ptr = shared_layout_ptr->GetBlockPtr<OSMNodeID, true>(
|
||||||
shared_memory_ptr, SharedDataLayout::OSM_NODE_ID_LIST);
|
shared_memory_ptr, SharedDataLayout::OSM_NODE_ID_LIST);
|
||||||
util::PackedVector<true> osmnodeid_list;
|
util::PackedVector<OSMNodeID, true> osmnodeid_list;
|
||||||
osmnodeid_list.reset(
|
osmnodeid_list.reset(
|
||||||
osmnodeid_ptr, shared_layout_ptr->num_entries[storage::SharedDataLayout::OSM_NODE_ID_LIST]);
|
osmnodeid_ptr, shared_layout_ptr->num_entries[storage::SharedDataLayout::OSM_NODE_ID_LIST]);
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ using namespace osrm::util;
|
|||||||
// Verify that the packed vector behaves as expected
|
// Verify that the packed vector behaves as expected
|
||||||
BOOST_AUTO_TEST_CASE(insert_and_retrieve_packed_test)
|
BOOST_AUTO_TEST_CASE(insert_and_retrieve_packed_test)
|
||||||
{
|
{
|
||||||
PackedVector<false> packed_ids;
|
PackedVector<OSMNodeID, false> packed_ids;
|
||||||
std::vector<OSMNodeID> original_ids;
|
std::vector<OSMNodeID> original_ids;
|
||||||
|
|
||||||
const constexpr std::size_t num_test_cases = 399;
|
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)
|
BOOST_AUTO_TEST_CASE(packed_vector_capacity_test)
|
||||||
{
|
{
|
||||||
PackedVector<false> packed_vec;
|
PackedVector<OSMNodeID, false> packed_vec;
|
||||||
const std::size_t original_size = packed_vec.capacity();
|
const std::size_t original_size = packed_vec.capacity();
|
||||||
std::vector<OSMNodeID> dummy_vec;
|
std::vector<OSMNodeID> dummy_vec;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user