Skip to content

Commit

Permalink
Revert part of commit f06151, that part actually made Fruit slightly …
Browse files Browse the repository at this point in the history
…slower now that the hash table is bigger.
  • Loading branch information
poletti-marco committed Sep 12, 2018
1 parent e66c410 commit bc7a2df
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 30 deletions.
20 changes: 2 additions & 18 deletions include/fruit/impl/data_structures/semistatic_graph.templates.h
Original file line number Diff line number Diff line change
Expand Up @@ -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});
}
Expand Down Expand Up @@ -101,20 +96,9 @@ SemistaticGraph<NodeId, Node>::SemistaticGraph(NodeIter first, NodeIter last, Me
}

using itr_t = typename HashSetWithArenaAllocator<NodeId>::iterator;
FixedSizeVector<NodeId, ArenaAllocator<NodeId>> node_ids_vector(
node_ids.size(), NodeId{}, ArenaAllocator<NodeId>(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<NodeId, InternalNodeId>(
indexing_iterator<typename FixedSizeVector<NodeId, ArenaAllocator<NodeId>>::iterator, sizeof(NodeData)>{
node_ids_vector.begin(),
0},
indexing_iterator<itr_t, sizeof(NodeData)>{node_ids.begin(), 0},
indexing_iterator<itr_t, sizeof(NodeData)>{node_ids.end(), node_ids.size() * sizeof(NodeData)},
node_ids.size(),
memory_pool);

Expand Down
2 changes: 1 addition & 1 deletion include/fruit/impl/data_structures/semistatic_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class SemistaticMap {
* The MemoryPool is only used during construction, the constructed object *can* outlive the memory pool.
*/
template <typename Iter>
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'.
Expand Down
5 changes: 2 additions & 3 deletions include/fruit/impl/data_structures/semistatic_map.templates.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ namespace impl {

template <typename Key, typename Value>
template <typename Iter>
SemistaticMap<Key, Value>::SemistaticMap(Iter values_begin, std::size_t num_values, MemoryPool& memory_pool) {
SemistaticMap<Key, Value>::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<Unsigned, ArenaAllocator<Unsigned>> count(num_buckets, 0, ArenaAllocator<Unsigned>(memory_pool));

Expand Down
16 changes: 8 additions & 8 deletions tests/data_structures/test_semistatic_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_empty():
MemoryPool memory_pool;
vector<pair<int, std::string>> values{};
SemistaticMap<int, std::string> map(values.begin(), values.size(), memory_pool);
SemistaticMap<int, std::string> map(values.begin(), values.end(), values.size(), memory_pool);
Assert(map.find(0) == nullptr);
Assert(map.find(2) == nullptr);
Assert(map.find(5) == nullptr);
Expand All @@ -48,7 +48,7 @@ def test_1_elem():
MemoryPool memory_pool;
vector<pair<int, std::string>> values{{2, "foo"}};
SemistaticMap<int, std::string> map(values.begin(), values.size(), memory_pool);
SemistaticMap<int, std::string> map(values.begin(), values.end(), values.size(), memory_pool);
Assert(map.find(0) == nullptr);
Assert(map.find(2) != nullptr);
Assert(map.at(2) == "foo");
Expand All @@ -66,7 +66,7 @@ def test_1_inserted_elem():
MemoryPool memory_pool;
vector<pair<int, std::string>> values{};
SemistaticMap<int, std::string> old_map(values.begin(), values.size(), memory_pool);
SemistaticMap<int, std::string> old_map(values.begin(), values.end(), values.size(), memory_pool);
vector<pair<int, std::string>, ArenaAllocator<pair<int, std::string>>> new_values(
{{2, "bar"}},
ArenaAllocator<pair<int, std::string>>(memory_pool));
Expand All @@ -88,7 +88,7 @@ def test_3_elem():
MemoryPool memory_pool;
vector<pair<int, std::string>> values{{1, "foo"}, {3, "bar"}, {4, "baz"}};
SemistaticMap<int, std::string> map(values.begin(), values.size(), memory_pool);
SemistaticMap<int, std::string> map(values.begin(), values.end(), values.size(), memory_pool);
Assert(map.find(0) == nullptr);
Assert(map.find(1) != nullptr);
Assert(map.at(1) == "foo");
Expand All @@ -111,7 +111,7 @@ def test_1_elem_2_inserted():
MemoryPool memory_pool;
vector<pair<int, std::string>> values{{1, "foo"}};
SemistaticMap<int, std::string> old_map(values.begin(), values.size(), memory_pool);
SemistaticMap<int, std::string> old_map(values.begin(), values.end(), values.size(), memory_pool);
vector<pair<int, std::string>, ArenaAllocator<pair<int, std::string>>> new_values(
{{3, "bar"}, {4, "baz"}},
ArenaAllocator<pair<int, std::string>>(memory_pool));
Expand All @@ -137,7 +137,7 @@ def test_3_elem_3_inserted():
int main() {
MemoryPool memory_pool;
vector<pair<int, std::string>> values{{1, "1"}, {3, "3"}, {5, "5"}};
SemistaticMap<int, std::string> old_map(values.begin(), values.size(), memory_pool);
SemistaticMap<int, std::string> old_map(values.begin(), values.end(), values.size(), memory_pool);
vector<pair<int, std::string>, ArenaAllocator<pair<int, std::string>>> new_values(
{{2, "2"}, {4, "4"}, {16, "16"}},
ArenaAllocator<pair<int, std::string>>(memory_pool));
Expand Down Expand Up @@ -168,7 +168,7 @@ def test_move_constructor():
int main() {
MemoryPool memory_pool;
vector<pair<int, std::string>> values{{1, "foo"}, {3, "bar"}, {4, "baz"}};
SemistaticMap<int, std::string> map1(values.begin(), values.size(), memory_pool);
SemistaticMap<int, std::string> map1(values.begin(), values.end(), values.size(), memory_pool);
SemistaticMap<int, std::string> map = std::move(map1);
Assert(map.find(0) == nullptr);
Assert(map.find(1) != nullptr);
Expand All @@ -191,7 +191,7 @@ def test_move_assignment():
int main() {
MemoryPool memory_pool;
vector<pair<int, std::string>> values{{1, "foo"}, {3, "bar"}, {4, "baz"}};
SemistaticMap<int, std::string> map1(values.begin(), values.size(), memory_pool);
SemistaticMap<int, std::string> map1(values.begin(), values.end(), values.size(), memory_pool);
SemistaticMap<int, std::string> map;
map = std::move(map1);
Assert(map.find(0) == nullptr);
Expand Down

0 comments on commit bc7a2df

Please sign in to comment.