diff options
| author | nodist <kevin.comas.git@gmail.com> | 2026-11-13 16:28:13 -0500 |
|---|---|---|
| committer | nodist <kevin.comas.git@gmail.com> | 2026-11-13 16:28:13 -0500 |
| commit | c3d23d3091c23978b12c140e6cfd964eff1d3986 (patch) | |
| tree | 3342a73aea427fa19d2b0936a98e37fbe479c85d /include/kpl/tree.h | |
| parent | 75c8828d804f45cf8f44af73bfe87e0f3eaf9a9e (diff) | |
Diffstat (limited to 'include/kpl/tree.h')
| -rw-r--r-- | include/kpl/tree.h | 61 |
1 files changed, 0 insertions, 61 deletions
diff --git a/include/kpl/tree.h b/include/kpl/tree.h deleted file mode 100644 index f3503d2..0000000 --- a/include/kpl/tree.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * KPL tree - */ - -#pragma once - -// tree_duplicates is a linked stack -#define KPL_TREE_HEADER(STRUCT_NAME) \ - struct STRUCT_NAME *tree_left, *tree_right, *tree_duplicates; \ - int32_t tree_height - -/* - * Recursive AVL saves 8 bytes per object (no need for parent pointer) and keeps the insertion and finding simple - */ -typedef struct _kpl_tree_node { - KPL_TREE_HEADER(_kpl_tree_node); -} kpl_tree_node; - -typedef enum : int32_t { - KPL_TREE_TREE_HEIGHT_INIT = 1 -} kpl_tree_enum; - -/* - * -1 search left, 1 search right, 0 found - */ -typedef int32_t kpl_tree_node_compare_fn(const void *node_a, const void *node_b); - -typedef void kpl_tree_node_free_fn(void *node); - -/* - * KPL needs trees with insertion and find operations, deletion is not needed, all nodes are freed on tree free - */ -typedef struct { - kpl_tree_node *root_node; - kpl_tree_node_compare_fn *node_compare_fn; - kpl_tree_node_free_fn *node_free_fn; -} kpl_tree; - -#define KPL_TREE_INIT_STATIC(COMPARE_FN, FREE_FN) \ - (kpl_tree) { .root_node = NULL, .node_compare_fn = COMPARE_FN, .node_free_fn = FREE_FN } - -inline void kpl_tree_init(kpl_tree *tree, kpl_tree_node_compare_fn node_compare_fn, - kpl_tree_node_free_fn node_free_fn) { - tree->root_node = NULL; - tree->node_compare_fn = node_compare_fn; - tree->node_free_fn = node_free_fn; -} - -void kpl_tree_free(kpl_tree *tree); - -/* - * *find is stack allocated - * NULL for not found - */ -void *kpl_tree_find(kpl_tree *tree, const void *find_node); - -/* - * *insert is heap allocated - * All inserts succeed, duplicates are added to *tree_duplicates - */ -void kpl_tree_insert(kpl_tree *tree, void *insert_node); |
