feat(lsm): binary tree iterators

This commit is contained in:
Jef Roosens 2023-12-22 22:07:09 +01:00
parent 8c2a7a640d
commit 5564e23ceb
Signed by: Jef Roosens
GPG key ID: B75D4F293C7052DB
5 changed files with 130 additions and 5 deletions

View file

@ -104,6 +104,33 @@ void test_remove_multiple() {
lsm_bt_free(bt);
}
void test_iter() {
char chars[] = "falcoep";
size_t char_count = sizeof(chars) / sizeof(char) - 1;
char sorted_chars[] = "aceflop";
BT_INIT();
for (size_t i = 0; i < char_count; i++) {
TEST_CHECK(lsm_bt_insert(bt, chars[i], (void *)(i + 1)) == lsm_error_ok);
}
lsm_bt_iterator iter;
lsm_bt_iter(&iter, bt);
char key;
const void *data;
size_t i = 0;
while (lsm_bt_iter_next(&data, &key, &iter)) {
TEST_CHECK_(key == sorted_chars[i], "%c == %c", key, sorted_chars[i]);
i++;
}
TEST_CHECK(i == char_count);
}
TEST_LIST = {
{ "bt init", test_init },
{ "bt insert first", test_insert_first },
@ -111,5 +138,6 @@ TEST_LIST = {
{ "bt insert multiple", test_insert_multiple },
{ "bt remove root", test_remove_root },
{ "bt remove multiple", test_remove_multiple },
{ "bt iter", test_iter },
{ NULL, NULL }
};