Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ callgrind.*
cmake-build-debug
.idea
*.log
_codeql_build_dir/
1 change: 1 addition & 0 deletions include/art/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <algorithm>
#include <array>
#include <cassert>
#include <cstdint>
#include <cstring>
#include <iostream>
#include <iterator>
Expand Down
11 changes: 8 additions & 3 deletions include/art/tree_it.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,11 @@ typename tree_it<T>::step &tree_it<T>::step::operator++() {
child_node_ = child_it_ != child_it_end_
? child_it_.get_child_node()
: nullptr;
key_[depth_ - 1] = child_it_ != child_it_end_
? child_it_.get_partial_key()
: '\0';
if (depth_ > 0) {
key_[depth_ - 1] = child_it_ != child_it_end_
? child_it_.get_partial_key()
: '\0';
}
return *this;
}

Expand Down Expand Up @@ -311,6 +313,9 @@ void tree_it<T>::seek_leaf() {
/* traverse up until a node on the right is found or stack gets empty */
for (; get_step().child_it_ == get_step().child_it_end_; ++get_step()) {
traversal_stack_.pop_back();
if (traversal_stack_.empty()) {
return;
}
if (get_step().child_node_ == root_) { // root guard
traversal_stack_.pop_back();
assert(traversal_stack_.empty());
Expand Down
39 changes: 39 additions & 0 deletions test/tree_it.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,45 @@ using std::string;
using std::to_string;

TEST_SUITE("tree_it") {
TEST_CASE("single element iteration") {
SUBCASE("iterate over single element") {
int value = 42;
art::art<int*> m;

m.set("key1", &value);

auto it = m.begin();
auto it_end = m.end();

// First element should be accessible
REQUIRE(it != it_end);
REQUIRE_EQ(&value, *it);
REQUIRE_EQ("key1", it.key());

// Increment past the only element
++it;

// Should now be at end
REQUIRE(it == it_end);
}

SUBCASE("iterate over single element with for loop") {
int value = 1;
art::art<int*> m;

m.set("key1", &value);

int count = 0;
for(auto itor = m.begin(); itor != m.end(); ++itor) {
REQUIRE_EQ("key1", itor.key());
REQUIRE_EQ(&value, *itor);
++count;
}

REQUIRE_EQ(1, count);
}
}

TEST_CASE("full lexicographic traversal") {
SUBCASE("controlled test") {
int int0 = 0;
Expand Down