2023-01-19 21:22:08 +01:00
|
|
|
#ifndef VIETER_TREE
|
|
|
|
#define VIETER_TREE
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2023-01-19 22:23:19 +01:00
|
|
|
#include <stdlib.h>
|
2023-01-19 21:22:08 +01:00
|
|
|
|
|
|
|
typedef struct vieter_tree vieter_tree;
|
|
|
|
|
|
|
|
typedef enum vieter_tree_error {
|
2023-01-19 22:23:19 +01:00
|
|
|
vieter_tree_ok = 0,
|
|
|
|
vieter_tree_already_present = 1,
|
|
|
|
vieter_tree_not_present = 2
|
2023-01-19 21:22:08 +01:00
|
|
|
} vieter_tree_error;
|
|
|
|
|
2023-01-28 09:09:17 +01:00
|
|
|
/*
|
|
|
|
* Allocate and initialize a new red-black binary tree.
|
|
|
|
*/
|
2023-01-19 22:23:19 +01:00
|
|
|
vieter_tree *vieter_tree_init();
|
|
|
|
|
2023-01-28 09:09:17 +01:00
|
|
|
/*
|
|
|
|
* Deallocate a red-black binary tree.
|
|
|
|
*/
|
2023-01-19 22:23:19 +01:00
|
|
|
void vieter_tree_free(vieter_tree *tree);
|
|
|
|
|
2023-01-28 09:09:17 +01:00
|
|
|
/*
|
|
|
|
* Insert a new entry into the tree.
|
|
|
|
*/
|
2023-01-19 22:23:19 +01:00
|
|
|
vieter_tree_error vieter_tree_insert(vieter_tree *tree, uint64_t key,
|
|
|
|
void *data);
|
|
|
|
|
2023-01-28 09:09:17 +01:00
|
|
|
/*
|
|
|
|
* Look for an entry in the tree.
|
|
|
|
*/
|
2023-01-19 22:23:19 +01:00
|
|
|
vieter_tree_error vieter_tree_search(void **out, vieter_tree *tree,
|
|
|
|
uint64_t key);
|
|
|
|
|
2023-01-28 09:09:17 +01:00
|
|
|
/*
|
|
|
|
* Remove a given entry from the tree.
|
|
|
|
*/
|
2023-01-19 22:23:19 +01:00
|
|
|
vieter_tree_error vieter_tree_remove(void **out, vieter_tree *tree,
|
|
|
|
uint64_t key);
|
|
|
|
|
2023-01-28 09:09:17 +01:00
|
|
|
/*
|
|
|
|
* Return how many entries are currently in the tree.
|
|
|
|
*/
|
2023-01-19 22:23:19 +01:00
|
|
|
uint64_t vieter_tree_size(vieter_tree *tree);
|
2023-01-19 21:22:08 +01:00
|
|
|
|
|
|
|
#endif
|