From 0c60a2aef88ad97da6f9b0d43ba288dc7b6fe110 Mon Sep 17 00:00:00 2001 From: Lauren Budorick Date: Tue, 24 May 2016 10:17:24 -0400 Subject: [PATCH] Minor cleanups + comments --- include/util/packed_vector.hpp | 13 +++++++++++-- unit_tests/util/packed_vector.cpp | 4 ++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/include/util/packed_vector.hpp b/include/util/packed_vector.hpp index 954a70e30..d84b9cb8d 100644 --- a/include/util/packed_vector.hpp +++ b/include/util/packed_vector.hpp @@ -2,6 +2,7 @@ #define PACKED_VECTOR_HPP #include "util/typedefs.hpp" +#include "util/shared_memory_vector_wrapper.hpp" #include #include @@ -15,12 +16,18 @@ const constexpr std::size_t BITSIZE = 33; const constexpr std::size_t ELEMSIZE = 64; const constexpr std::size_t PACKSIZE = BITSIZE * ELEMSIZE; -std::size_t PackedVectorSize(std::size_t elements) +/** + * Returns the size of the packed vector datastructure with `elements` packed elements (the size of its underlying vector) + */ +inline std::size_t PackedVectorSize(std::size_t elements) { return ceil(float(elements) / ELEMSIZE) * BITSIZE; }; -std::size_t PackedVectorCapacity(std::size_t vec_size) +/** + * Returns the capacity of a packed vector with underlying vector size `vec_size` + */ +inline std::size_t PackedVectorCapacity(std::size_t vec_size) { return floor(float(vec_size) / BITSIZE) * ELEMSIZE; } @@ -33,11 +40,13 @@ std::size_t PackedVectorCapacity(std::size_t vec_size) template class PackedVector { public: + PackedVector() = default; void push_back(OSMNodeID incoming_node_id) { std::uint64_t node_id = static_cast(incoming_node_id); + // mask incoming values, just in case they are > bitsize const std::uint64_t incoming_mask = static_cast(pow(2, BITSIZE)) - 1; node_id = node_id & incoming_mask; diff --git a/unit_tests/util/packed_vector.cpp b/unit_tests/util/packed_vector.cpp index 9995c7be0..6b69add91 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;