diff --git a/include/fruit/impl/data_structures/semistatic_graph.templates.h b/include/fruit/impl/data_structures/semistatic_graph.templates.h index 06aed8d5..37e9484d 100644 --- a/include/fruit/impl/data_structures/semistatic_graph.templates.h +++ b/include/fruit/impl/data_structures/semistatic_graph.templates.h @@ -45,11 +45,6 @@ struct indexing_iterator { index += index_increment; } - void operator+=(std::size_t n) { - iter += n; - index += index_increment * n; - } - auto operator*() -> decltype(std::make_pair(*iter, SemistaticGraphInternalNodeId{index})) { return std::make_pair(*iter, SemistaticGraphInternalNodeId{index}); } @@ -101,20 +96,9 @@ SemistaticGraph::SemistaticGraph(NodeIter first, NodeIter last, Me } using itr_t = typename HashSetWithArenaAllocator::iterator; - FixedSizeVector> node_ids_vector( - node_ids.size(), NodeId{}, ArenaAllocator(memory_pool)); - { - itr_t itr = node_ids.begin(); - for (std::size_t i = 0; i < node_ids.size(); ++i, ++itr) { - node_ids_vector[i] = *itr; - } - } - - node_index_map = SemistaticMap( - indexing_iterator>::iterator, sizeof(NodeData)>{ - node_ids_vector.begin(), - 0}, + indexing_iterator{node_ids.begin(), 0}, + indexing_iterator{node_ids.end(), node_ids.size() * sizeof(NodeData)}, node_ids.size(), memory_pool); diff --git a/include/fruit/impl/data_structures/semistatic_map.h b/include/fruit/impl/data_structures/semistatic_map.h index aa5bf3a0..cd03cc26 100644 --- a/include/fruit/impl/data_structures/semistatic_map.h +++ b/include/fruit/impl/data_structures/semistatic_map.h @@ -92,7 +92,7 @@ class SemistaticMap { * The MemoryPool is only used during construction, the constructed object *can* outlive the memory pool. */ template - SemistaticMap(Iter begin, std::size_t num_values, MemoryPool& memory_pool); + SemistaticMap(Iter begin, Iter end, std::size_t num_values, MemoryPool& memory_pool); // Creates a shallow copy of `map' with the additional elements in new_elements. // The keys in new_elements must be unique and must not be present in `map'. diff --git a/include/fruit/impl/data_structures/semistatic_map.templates.h b/include/fruit/impl/data_structures/semistatic_map.templates.h index 5b94337b..7c62f247 100644 --- a/include/fruit/impl/data_structures/semistatic_map.templates.h +++ b/include/fruit/impl/data_structures/semistatic_map.templates.h @@ -40,11 +40,10 @@ namespace impl { template template -SemistaticMap::SemistaticMap(Iter values_begin, std::size_t num_values, MemoryPool& memory_pool) { +SemistaticMap::SemistaticMap( + Iter values_begin, Iter values_end, std::size_t num_values, MemoryPool& memory_pool) { NumBits num_bits = pickNumBits(num_values); std::size_t num_buckets = size_t(1) << num_bits; - Iter values_end = values_begin; - values_end += num_values; FixedSizeVector> count(num_buckets, 0, ArenaAllocator(memory_pool)); diff --git a/tests/data_structures/test_semistatic_map.py b/tests/data_structures/test_semistatic_map.py index c3399896..e51f13e1 100644 --- a/tests/data_structures/test_semistatic_map.py +++ b/tests/data_structures/test_semistatic_map.py @@ -31,7 +31,7 @@ def test_empty(): MemoryPool memory_pool; vector> values{}; - SemistaticMap map(values.begin(), values.size(), memory_pool); + SemistaticMap map(values.begin(), values.end(), values.size(), memory_pool); Assert(map.find(0) == nullptr); Assert(map.find(2) == nullptr); Assert(map.find(5) == nullptr); @@ -48,7 +48,7 @@ def test_1_elem(): MemoryPool memory_pool; vector> values{{2, "foo"}}; - SemistaticMap map(values.begin(), values.size(), memory_pool); + SemistaticMap map(values.begin(), values.end(), values.size(), memory_pool); Assert(map.find(0) == nullptr); Assert(map.find(2) != nullptr); Assert(map.at(2) == "foo"); @@ -66,7 +66,7 @@ def test_1_inserted_elem(): MemoryPool memory_pool; vector> values{}; - SemistaticMap old_map(values.begin(), values.size(), memory_pool); + SemistaticMap old_map(values.begin(), values.end(), values.size(), memory_pool); vector, ArenaAllocator>> new_values( {{2, "bar"}}, ArenaAllocator>(memory_pool)); @@ -88,7 +88,7 @@ def test_3_elem(): MemoryPool memory_pool; vector> values{{1, "foo"}, {3, "bar"}, {4, "baz"}}; - SemistaticMap map(values.begin(), values.size(), memory_pool); + SemistaticMap map(values.begin(), values.end(), values.size(), memory_pool); Assert(map.find(0) == nullptr); Assert(map.find(1) != nullptr); Assert(map.at(1) == "foo"); @@ -111,7 +111,7 @@ def test_1_elem_2_inserted(): MemoryPool memory_pool; vector> values{{1, "foo"}}; - SemistaticMap old_map(values.begin(), values.size(), memory_pool); + SemistaticMap old_map(values.begin(), values.end(), values.size(), memory_pool); vector, ArenaAllocator>> new_values( {{3, "bar"}, {4, "baz"}}, ArenaAllocator>(memory_pool)); @@ -137,7 +137,7 @@ def test_3_elem_3_inserted(): int main() { MemoryPool memory_pool; vector> values{{1, "1"}, {3, "3"}, {5, "5"}}; - SemistaticMap old_map(values.begin(), values.size(), memory_pool); + SemistaticMap old_map(values.begin(), values.end(), values.size(), memory_pool); vector, ArenaAllocator>> new_values( {{2, "2"}, {4, "4"}, {16, "16"}}, ArenaAllocator>(memory_pool)); @@ -168,7 +168,7 @@ def test_move_constructor(): int main() { MemoryPool memory_pool; vector> values{{1, "foo"}, {3, "bar"}, {4, "baz"}}; - SemistaticMap map1(values.begin(), values.size(), memory_pool); + SemistaticMap map1(values.begin(), values.end(), values.size(), memory_pool); SemistaticMap map = std::move(map1); Assert(map.find(0) == nullptr); Assert(map.find(1) != nullptr); @@ -191,7 +191,7 @@ def test_move_assignment(): int main() { MemoryPool memory_pool; vector> values{{1, "foo"}, {3, "bar"}, {4, "baz"}}; - SemistaticMap map1(values.begin(), values.size(), memory_pool); + SemistaticMap map1(values.begin(), values.end(), values.size(), memory_pool); SemistaticMap map; map = std::move(map1); Assert(map.find(0) == nullptr);