2023-10-13 12:45:48 +02:00
|
|
|
#ifndef LSM_TRIE
|
|
|
|
#define LSM_TRIE
|
|
|
|
|
|
|
|
#include "lsm.h"
|
2023-10-13 13:07:40 +02:00
|
|
|
#include "lsm/str.h"
|
2023-10-13 12:45:48 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2023-10-13 13:07:40 +02:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2023-11-16 21:52:20 +01:00
|
|
|
lsm_error lsm_trie_insert(lsm_trie *trie, const lsm_str *key, void *data);
|
2023-10-13 13:07:40 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Search for an element in the trie.
|
|
|
|
*
|
2023-11-16 21:52:20 +01:00
|
|
|
* @param out where to store data pointer, if present
|
2023-10-13 13:07:40 +02:00
|
|
|
* @param trie trie to search in
|
|
|
|
* @param key key to search with
|
|
|
|
*/
|
2023-11-16 21:52:20 +01:00
|
|
|
lsm_error lsm_trie_search(void **out, const lsm_trie *trie, const lsm_str *key);
|
2023-10-13 13:07:40 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2023-11-16 21:52:20 +01:00
|
|
|
lsm_error lsm_trie_remove(void **out, lsm_trie *trie, const lsm_str *key);
|
2023-10-13 13:07:40 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the size of a trie
|
|
|
|
*
|
|
|
|
* @param trie trie to return size for
|
|
|
|
*/
|
2023-11-14 10:49:12 +01:00
|
|
|
uint64_t lsm_trie_size(const lsm_trie *trie);
|
2023-10-13 13:07:40 +02:00
|
|
|
|
2023-10-13 12:45:48 +02:00
|
|
|
#endif
|