lander/lsm/include/lsm/trie.h

61 lines
1.3 KiB
C

#ifndef LSM_TRIE
#define LSM_TRIE
#include "lsm.h"
#include "lsm/str.h"
/**
* A struct representing a trie
*/
typedef struct lsm_trie lsm_trie;
/**
* Initialize a new trie.
*
* @param ptr where to store the newly allocated pointer
*/
lsm_error lsm_trie_init(lsm_trie **ptr);
/**
* Deallocate an entire trie, including all its nodes
*
* @param trie trie to free
*/
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, const lsm_str *key, void *data);
/**
* Search for an element in the trie.
*
* @param out where to store data pointer, if present
* @param trie trie to search in
* @param key key to search with
*/
lsm_error lsm_trie_search(void **out, const lsm_trie *trie, const 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 **out, lsm_trie *trie, const lsm_str *key);
/**
* Return the size of a trie
*
* @param trie trie to return size for
*/
uint64_t lsm_trie_size(const lsm_trie *trie);
#endif