refactor(lsm): allow modules to import other internal header files

lsm
Jef Roosens 2023-10-13 13:07:40 +02:00
parent c327be80e9
commit 0548efda97
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
9 changed files with 54 additions and 4 deletions

View File

@ -3,7 +3,7 @@ LIB_FILENAME = liblsm.a
BUILD_DIR = build BUILD_DIR = build
SRC_DIR = src SRC_DIR = src
TEST_DIR = test 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 # -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 # make and makes make aware that a header file has been changed, ensuring an

View File

@ -2,6 +2,7 @@
#define LSM_TRIE #define LSM_TRIE
#include "lsm.h" #include "lsm.h"
#include "lsm/str.h"
/** /**
* A struct representing a trie * A struct representing a trie
@ -22,4 +23,38 @@ lsm_error lsm_trie_init(lsm_trie **ptr);
*/ */
void lsm_trie_free(lsm_trie *trie); 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 #endif

View File

@ -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

View File

@ -1,6 +1,6 @@
#include <stdlib.h> #include <stdlib.h>
#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_error lsm_bt_node_init(lsm_bt_node **ptr, const char key, void *data) {
lsm_bt_node *node = calloc(1, sizeof(lsm_bt_node)); lsm_bt_node *node = calloc(1, sizeof(lsm_bt_node));

View File

@ -3,7 +3,7 @@
#include <string.h> #include <string.h>
#include "lsm.h" #include "lsm.h"
#include "lsm_str_internal.h" #include "lsm/str_internal.h"
lsm_error lsm_str_init_zero(lsm_str **ptr) { lsm_error lsm_str_init_zero(lsm_str **ptr) {
lsm_str *str = calloc(1, sizeof(lsm_str)); lsm_str *str = calloc(1, sizeof(lsm_str));

View File

@ -0,0 +1 @@
#include "lsm/trie_internal.h"

View File

@ -1,5 +1,5 @@
#include "test.h" #include "test.h"
#include "lsm_bt_internal.h" #include "lsm/bt_internal.h"
#define BT_INIT() \ #define BT_INIT() \
lsm_bt *bt; \ lsm_bt *bt; \