Skip to content

Commit

Permalink
Fix empty tree node iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
jhrotko committed Jun 2, 2020
1 parent 2470513 commit fa6ea84
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
11 changes: 3 additions & 8 deletions include/sdsl/k2_tree_iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,7 @@ namespace sdsl
this->curr_j = other->curr_j;
}

~node_iterator()
{
}
~node_iterator() {}

value_type operator*() const
{
Expand All @@ -486,17 +484,13 @@ namespace sdsl
{
for (value_type j = curr_j; j < tree->get_number_nodes(); j++)
if (tree->adj(i, j))
{
return update_state(i);
}
for (value_type j = 0; j < tree->get_number_nodes(); j++)
{
if (j == i)
continue;
if (tree->adj(j, i))
{
return update_state(i);
}
}
curr_j = 0;
}
Expand All @@ -513,6 +507,7 @@ namespace sdsl

node_iterator<k2_tree> end()
{
if(tree == NULL) return *this;
node_iterator<k2_tree> it = *this;
value_type num_nodes = it.tree->get_number_nodes();
*(it._ptr) = it.tree->get_number_nodes(); //end node
Expand Down Expand Up @@ -542,7 +537,7 @@ namespace sdsl

return *this;
}
};
}; // namespace sdsl

} // namespace sdsl

Expand Down
8 changes: 6 additions & 2 deletions test/k2_tree_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,14 +394,18 @@ TYPED_TEST(k2_tree_test_k_2, node_iterator_test) {
node_iterator++;
ASSERT_EQ(*node_iterator, (size_t)3);

node_iterator = tree.node_end();
ASSERT_EQ(*node_iterator, (size_t)4);
node_iterator++;
ASSERT_EQ(*node_iterator, *tree.node_end());

auto other_iterator = tree.node_begin();
swap(other_iterator, node_iterator);
ASSERT_EQ(*other_iterator, *tree.node_end());
ASSERT_EQ(*node_iterator, *tree.node_begin());
}

TYPED_TEST(k2_tree_test_k_2, node_iterator_empty) {
TypeParam empty_tree;
ASSERT_TRUE(empty_tree.node_begin() == empty_tree.node_end());
}

TYPED_TEST_CASE(k2_tree_test_k_3, k_3_implementations);
Expand Down

0 comments on commit fa6ea84

Please sign in to comment.