72 lines
1.6 KiB
C
72 lines
1.6 KiB
C
#ifndef LSM_BT
|
|
#define LSM_BT
|
|
|
|
#include "lsm.h"
|
|
|
|
/**
|
|
* A binary tree implementation using char values as keys
|
|
*/
|
|
typedef struct lsm_bt lsm_bt;
|
|
|
|
/**
|
|
* Initialize a new binary tree
|
|
*
|
|
* @param ptr where to store newly allocated pointer
|
|
*/
|
|
lsm_error lsm_bt_init(lsm_bt **ptr);
|
|
|
|
/**
|
|
* Deallocate an entire binary tree, including all its nodes
|
|
*/
|
|
void lsm_bt_free(lsm_bt *bt);
|
|
|
|
/**
|
|
* Remove the binary tree's entire contents, but keep the struct allocated.
|
|
*/
|
|
void lsm_bt_clear(lsm_bt *bt);
|
|
|
|
/**
|
|
* Return the size of the binary tree
|
|
*/
|
|
uint64_t lsm_bt_size(const lsm_bt *bt);
|
|
|
|
/**
|
|
* Search for the data stored behind the given key.
|
|
*
|
|
* @param out pointer to store data pointer in
|
|
* @param bt binary tree to search
|
|
* @param key key to search
|
|
*/
|
|
lsm_error lsm_bt_search(void **out, lsm_bt *bt, char key);
|
|
|
|
/**
|
|
* Insert a new data value into the tree with the given key.
|
|
*
|
|
* @param bt binary tree to insert into
|
|
* @param key key to insert
|
|
* @param data data to store
|
|
*/
|
|
lsm_error lsm_bt_insert(lsm_bt *bt, char key, void *data);
|
|
|
|
/**
|
|
* Remove the given key from the binary tree. Ownership of the data pointer is
|
|
* returned to the caller.
|
|
*
|
|
* @param out address to write data pointer to
|
|
* @param bt binary tree to remove from
|
|
* @param key key to remove
|
|
*/
|
|
lsm_error lsm_bt_remove(void **out, lsm_bt *bt, char key);
|
|
|
|
/**
|
|
* Replace the data at an existing key with new data, returning the old.
|
|
*
|
|
* @param out address to write old data pointer to
|
|
* @param bt binary tree to replace in
|
|
* @param key key to replace at
|
|
* @param data new data to store
|
|
*/
|
|
lsm_error lsm_bt_replace(void **out, lsm_bt *bt, char key, void *data);
|
|
|
|
#endif
|