From 682f422e3ce7c64c0dbc362a113ec69543efb58e Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Sat, 14 Oct 2023 14:53:42 +0200 Subject: [PATCH] feat(lsm): probably working trie insert --- lsm/src/trie/lsm_trie.c | 23 +++++++++++++++-------- lsm/test/trie/trie_fuzzy.c | 4 ++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lsm/src/trie/lsm_trie.c b/lsm/src/trie/lsm_trie.c index e72c288..a8b7d82 100644 --- a/lsm/src/trie/lsm_trie.c +++ b/lsm/src/trie/lsm_trie.c @@ -1,3 +1,4 @@ +#include #include #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; } diff --git a/lsm/test/trie/trie_fuzzy.c b/lsm/test/trie/trie_fuzzy.c index 9974a68..9462c27 100644 --- a/lsm/test/trie/trie_fuzzy.c +++ b/lsm/test/trie/trie_fuzzy.c @@ -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} };