From c84c3f459919aa8db2a24c8461aab9e547be961f Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Tue, 23 Jun 2020 07:39:29 +0200 Subject: Comments, white space errors --- src/tree.h | 48 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 11 deletions(-) (limited to 'src/tree.h') diff --git a/src/tree.h b/src/tree.h index 38b4b38..98019c8 100644 --- a/src/tree.h +++ b/src/tree.h @@ -4,11 +4,43 @@ * License: MIT * */ +/** + * Binary tree designed to serve as a static lookup table. + * On the fly rebalancing is not intended. + * + * The char* _key is used as a primary key, the tree can + * carry any generic payload in void* _data. + * + * The root does not need special initialization. + * + * A query with tree_get() returns _data on an exact match, + * NULL if no matching key is found. + * + * To free the memory, do not use free() on root, but + * tree_destroy() instead. _key and _data can be freed + * by providing _TREE_FREE_DATA | _TREE_FREE_KEY. + * + * Example: + * + * struct tree_node* root = NULL; + * + * // A String is used as data + * tree_insert ( &root, "one", "data one" ); + * tree_insert ( &root, "two", "data two" ); + * + * printf( "%s\n", tree_get( &root, "two" ) ); + * + * tree_destroy ( &root, 0 ); + * + **/ + #pragma once #include #include +#include +//TODO remove #include #define _TREE_FREE_DATA 0x01 @@ -23,7 +55,11 @@ struct tree_node { int tree_insert ( struct tree_node** _root, char* _key, void* _data ); -int tree_balance( struct tree_node** _root ); +/** + * Inserts the given list into the tree, achieving optimal depth. + * Expects a sorted list. + * */ +int tree_balanced_insert( struct tree_node** _root, void* _data[], char* _key[], unsigned int _len); /** * Returns (void*)node->data on success, NULL on failure @@ -31,13 +67,3 @@ int tree_balance( struct tree_node** _root ); void* tree_get ( struct tree_node** _root, char* _query ); int tree_destroy( struct tree_node** _root, uint8_t _options ); - -/** - * ignore-case alphabetical string compare - * returns: - * 0 :: _1 == _2 - * -1 :: _1 < _2 - * +1 :: _1 > _2 - * */ -int string_compare ( char* _1, char* _2 ); - -- cgit v1.2.3