feat(lsm): probably working trie insert
parent
ef8129b8eb
commit
682f422e3c
|
@ -1,3 +1,4 @@
|
|||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "lsm.h"
|
||||
|
@ -101,20 +102,26 @@ lsm_error lsm_trie_insert(lsm_trie *trie, lsm_str *key, void *data) {
|
|||
}
|
||||
|
||||
// split_node replaces the original node as the new child node
|
||||
// bottom_node here is always the same value as next_node
|
||||
lsm_trie_node *bottom_node;
|
||||
lsm_bt_replace((void **)&bottom_node, &node->bt, c, split_node);
|
||||
|
||||
// The old child node now becomes the child of split_node
|
||||
lsm_bt_insert(&split_node->bt, lsm_str_char(key, index + cmp),
|
||||
bottom_node);
|
||||
// The old next node now becomes the child of split_node
|
||||
lsm_bt_insert(&split_node->bt, lsm_str_char(&next_node->skip, cmp),
|
||||
next_node);
|
||||
|
||||
// The new node splits the edge into two parts, so the new node will have
|
||||
// the remaining part of the skip (minus the one character) as its skip
|
||||
lsm_str_substr(&split_node->skip, &next_node->skip, cmp + 1,
|
||||
lsm_str_len(&next_node->skip));
|
||||
// split_node's skip has not been initialized yet, so we can simply
|
||||
// overwrite it with bottom_node's skip
|
||||
split_node->skip = next_node->skip;
|
||||
|
||||
// The new node splits the edge into two parts, so the new split node will
|
||||
// have the first part of the skip (minus the one character) as its
|
||||
// skip
|
||||
lsm_str_substr(&next_node->skip, &split_node->skip, cmp + 1,
|
||||
lsm_str_len(&split_node->skip));
|
||||
|
||||
// The old node keeps the first part of the skip
|
||||
lsm_str_truncate(&next_node->skip, cmp);
|
||||
lsm_str_truncate(&split_node->skip, cmp);
|
||||
|
||||
next_node = split_node;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ void test_fuzzy() {
|
|||
|
||||
for (int len = 1; len < 25; len += 5) {
|
||||
for (int count = 10; count <= 500; count += 10) {
|
||||
for (int i = 0; i < 1; i++) {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
counter++;
|
||||
|
||||
config.seed = rand();
|
||||
|
@ -30,6 +30,6 @@ void test_fuzzy() {
|
|||
}
|
||||
|
||||
TEST_LIST = {
|
||||
/* { "trie fuzzy", test_fuzzy }, */
|
||||
{ "trie fuzzy", test_fuzzy },
|
||||
{ NULL, NULL}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue