diff --git a/lsm/config.mk b/lsm/config.mk index c453c6a..310b7c4 100644 --- a/lsm/config.mk +++ b/lsm/config.mk @@ -3,7 +3,7 @@ LIB_FILENAME = liblsm.a BUILD_DIR = build SRC_DIR = src TEST_DIR = test -INC_DIRS = include +INC_DIRS = include src/_include # -MMD: generate a .d file for every source file. This file can be imported by # make and makes make aware that a header file has been changed, ensuring an diff --git a/lsm/include/lsm/trie.h b/lsm/include/lsm/trie.h index c50d1b3..7fd6b5b 100644 --- a/lsm/include/lsm/trie.h +++ b/lsm/include/lsm/trie.h @@ -2,6 +2,7 @@ #define LSM_TRIE #include "lsm.h" +#include "lsm/str.h" /** * A struct representing a trie @@ -22,4 +23,38 @@ lsm_error lsm_trie_init(lsm_trie **ptr); */ void lsm_trie_free(lsm_trie *trie); +/** + * Insert a new element into the trie using the specified key. + * + * @param trie trie to insert into + * @param key key to insert data with + * @param data data to insert + */ +lsm_error lsm_trie_insert(lsm_trie *trie, lsm_str *key, void *data); + +/** + * Search for an element in the trie. + * + * @param out where to store data opinter, if present + * @param trie trie to search in + * @param key key to search with + */ +lsm_error lsm_trie_search(void **data, lsm_trie *trie, lsm_str *key); + +/** + * Remove an element from the trie. + * + * @param out where to store the removed data pointer, if present. + * @param trie trie to remove from + * @param key key to remove + */ +lsm_error lsm_trie_remove(void **data, lsm_trie *trie, lsm_str *key); + +/** + * Return the size of a trie + * + * @param trie trie to return size for + */ +uint64_t lsm_trie_size(lsm_trie *trie); + #endif diff --git a/lsm/src/bt/lsm_bt_internal.h b/lsm/src/_include/lsm/bt_internal.h similarity index 100% rename from lsm/src/bt/lsm_bt_internal.h rename to lsm/src/_include/lsm/bt_internal.h diff --git a/lsm/src/string/lsm_str_internal.h b/lsm/src/_include/lsm/str_internal.h similarity index 100% rename from lsm/src/string/lsm_str_internal.h rename to lsm/src/_include/lsm/str_internal.h diff --git a/lsm/src/_include/lsm/trie_internal.h b/lsm/src/_include/lsm/trie_internal.h new file mode 100644 index 0000000..4fb7037 --- /dev/null +++ b/lsm/src/_include/lsm/trie_internal.h @@ -0,0 +1,14 @@ +#ifndef LSM_TRIE_INTERNAL +#define LSM_TRIE_INTERNAL + +#include "lsm/bt_internal.h" +#include "lsm/str_internal.h" +#include "lsm/trie.h" + +typedef struct lsm_trie_node { + lsm_bt bt; + lsm_str skip; + char c; +} lsm_trie_node; + +#endif diff --git a/lsm/src/bt/lsm_bt.c b/lsm/src/bt/lsm_bt.c index d6e8699..da08cbd 100644 --- a/lsm/src/bt/lsm_bt.c +++ b/lsm/src/bt/lsm_bt.c @@ -1,6 +1,6 @@ #include -#include "lsm_bt_internal.h" +#include "lsm/bt_internal.h" lsm_error lsm_bt_node_init(lsm_bt_node **ptr, const char key, void *data) { lsm_bt_node *node = calloc(1, sizeof(lsm_bt_node)); diff --git a/lsm/src/string/lsm_str.c b/lsm/src/str/lsm_str.c similarity index 96% rename from lsm/src/string/lsm_str.c rename to lsm/src/str/lsm_str.c index 81e8797..38bce13 100644 --- a/lsm/src/string/lsm_str.c +++ b/lsm/src/str/lsm_str.c @@ -3,7 +3,7 @@ #include #include "lsm.h" -#include "lsm_str_internal.h" +#include "lsm/str_internal.h" lsm_error lsm_str_init_zero(lsm_str **ptr) { lsm_str *str = calloc(1, sizeof(lsm_str)); diff --git a/lsm/src/trie/lsm_trie.c b/lsm/src/trie/lsm_trie.c new file mode 100644 index 0000000..568decb --- /dev/null +++ b/lsm/src/trie/lsm_trie.c @@ -0,0 +1 @@ +#include "lsm/trie_internal.h" diff --git a/lsm/test/bt/bt.c b/lsm/test/bt/bt.c index f2d2781..1900305 100644 --- a/lsm/test/bt/bt.c +++ b/lsm/test/bt/bt.c @@ -1,5 +1,5 @@ #include "test.h" -#include "lsm_bt_internal.h" +#include "lsm/bt_internal.h" #define BT_INIT() \ lsm_bt *bt; \