267 while (parent && node == parent->
next) {
292 while (parent && node == parent->
prev) {
391 void* data = node->
data;
392 int c = cmp(cmp_arg, data);
437 return node ? node->
data : 0;
451 return node ? node->
data : 0;
475 void* data = node->
data;
476 int c = cmp(cmp_arg, data);
519 return node ? node->
data : 0;
533 return node ? node->
data : 0;
552 void* data = node->
data;
553 int c = cmp(cmp_arg, data);
591 return node ? node->
data : 0;
605 return node ? node->
data : 0;
629 void* data = node->
data;
630 int c = cmp(cmp_arg, data);
673 return node ? node->
data : 0;
687 return node ? node->
data : 0;
706 void* data = node->
data;
707 int c = cmp(cmp_arg, data);
745 return node ? node->
data : 0;
759 return node ? node->
data : 0;
852 return tree->
root == 0;
Data structure node.
Definition: tommytypes.h:242
tommy_size_t index
Index of the node.
Definition: tommytypes.h:269
struct tommy_node_struct * next
Next node.
Definition: tommytypes.h:247
struct tommy_node_struct * prev
Previous node.
Definition: tommytypes.h:253
void * data
Pointer to the element containing the node.
Definition: tommytypes.h:260
Tree container type.
Definition: tommytree.h:146
tommy_tree_node * root
Root node.
Definition: tommytree.h:147
tommy_size_t count
Number of elements.
Definition: tommytree.h:149
tommy_compare_func * cmp
Comparison function.
Definition: tommytree.h:148
Doubly linked list for collisions into hashtables.
TOMMY_API void tommy_tree_foreach(tommy_tree *tree, tommy_foreach_func *func)
Calls the specified function for each element in the tree.
void * tommy_tree_search_compare(tommy_tree *tree, tommy_compare_func *cmp, const void *cmp_arg)
Searches an element in the tree with a specific comparison function.
Definition: tommytree.h:433
void * tommy_tree_remove(tommy_tree *tree, const void *data)
Searches and removes an element from the tree.
Definition: tommytree.h:789
TOMMY_API void tommy_tree_insert(tommy_tree *tree, tommy_tree_node *node, void *data)
Inserts an element in the tree, allowing duplicate keys.
tommy_node tommy_tree_node
Tree node.
Definition: tommytree.h:140
void tommy_tree_init(tommy_tree *tree, tommy_compare_func *cmp)
Initializes the tree.
Definition: tommytree.h:157
TOMMY_API void * tommy_tree_remove_existing(tommy_tree *tree, tommy_tree_node *node)
Removes an element from the tree.
tommy_tree_node * tommy_tree_prev(tommy_tree_node *node)
Gets the node preceding the specified one in tree order.
Definition: tommytree.h:282
tommy_tree_node * tommy_tree_head(tommy_tree *tree)
Gets the head (smallest) node in the tree.
Definition: tommytree.h:306
void * tommy_tree_remove_head(tommy_tree *tree)
Removes and returns the head (smallest) element.
Definition: tommytree.h:344
tommy_tree_node * tommy_tree_find_greater(tommy_tree *tree, const void *data)
Finds the first node in tree order with key strictly greater than the specified one.
Definition: tommytree.h:573
void * tommy_tree_search_greater_equal(tommy_tree *tree, const void *data)
Searches an element in the tree with key greater or equal than the specified one.
Definition: tommytree.h:529
void * tommy_tree_remove_compare(tommy_tree *tree, tommy_compare_func *cmp, const void *cmp_arg)
Searches and removes an element from the tree with a specific comparison function.
Definition: tommytree.h:772
void * tommy_tree_remove_tail(tommy_tree *tree)
Removes and returns the tail (greatest) element.
Definition: tommytree.h:360
tommy_tree_node * tommy_tree_find_compare(tommy_tree *tree, tommy_compare_func *cmp, const void *cmp_arg)
Finds the first equal node in the tree with a specific comparison function.
Definition: tommytree.h:384
void * tommy_tree_search_greater(tommy_tree *tree, const void *data)
Searches the first element in tree order with key strictly greater than the specified one.
Definition: tommytree.h:601
tommy_tree_node * tommy_tree_find(tommy_tree *tree, const void *data)
Finds the first equal node in the tree.
Definition: tommytree.h:414
tommy_tree_node * tommy_tree_next(tommy_tree_node *node)
Gets the node following the specified one in tree order.
Definition: tommytree.h:257
tommy_tree_node * tommy_tree_find_less_compare(tommy_tree *tree, tommy_compare_func *cmp, const void *cmp_arg)
Finds the last node in tree order with key strictly less than the specified one using a specific comp...
Definition: tommytree.h:699
struct tommy_tree_struct tommy_tree
Tree container type.
TOMMY_API void tommy_tree_to_list(tommy_tree *tree, tommy_list *list)
Transfers all elements from the tree to the tail of a list in tree order.
void tommy_tree_clear(tommy_tree *tree)
Removes all elements, preserving the comparison function.
Definition: tommytree.h:189
TOMMY_API void * tommy_tree_insert_unique(tommy_tree *tree, tommy_tree_node *node, void *data)
Inserts an element only if no equal element is already contained.
void tommy_tree_swap(tommy_tree *first, tommy_tree *second)
Exchanges the contents of two initialized trees, including their comparison functions.
Definition: tommytree.h:173
TOMMY_API tommy_size_t tommy_tree_memory_usage(const tommy_tree *tree)
Gets the size of allocated memory.
tommy_tree_node * tommy_tree_parent(tommy_tree_node *node)
Gets the parent of the specified node.
Definition: tommytree.h:245
tommy_tree_node * tommy_tree_find_greater_equal(tommy_tree *tree, const void *data)
Finds a node in the tree with key greater or equal than the specified one.
Definition: tommytree.h:496
tommy_tree_node * tommy_tree_find_greater_equal_compare(tommy_tree *tree, tommy_compare_func *cmp, const void *cmp_arg)
Finds a node in the tree with key greater or equal than the specified one with a specific comparison ...
Definition: tommytree.h:468
tommy_size_t tommy_tree_count(const tommy_tree *tree)
Gets the number of elements.
Definition: tommytree.h:861
tommy_tree_node * tommy_tree_find_less_equal(tommy_tree *tree, const void *data)
Finds a node in the tree with key less or equal than the specified one.
Definition: tommytree.h:650
void * tommy_tree_search_less_compare(tommy_tree *tree, tommy_compare_func *cmp, const void *cmp_arg)
Searches the last element in tree order with key strictly less than the specified one using a specifi...
Definition: tommytree.h:741
tommy_tree_node * tommy_tree_tail(tommy_tree *tree)
Gets the tail (greatest) node in the tree.
Definition: tommytree.h:325
void * tommy_tree_search_less_equal_compare(tommy_tree *tree, tommy_compare_func *cmp, const void *cmp_arg)
Searches an element in the tree with key less or equal than the specified one with a specific compari...
Definition: tommytree.h:669
void * tommy_tree_search_greater_compare(tommy_tree *tree, tommy_compare_func *cmp, const void *cmp_arg)
Searches the first element in tree order with key strictly greater than the specified one using a spe...
Definition: tommytree.h:587
void * tommy_tree_search(tommy_tree *tree, const void *data)
Searches an element in the tree.
Definition: tommytree.h:447
tommy_tree_node * tommy_tree_find_less(tommy_tree *tree, const void *data)
Finds the last node in tree order with key strictly less than the specified one.
Definition: tommytree.h:727
void * tommy_tree_search_less_equal(tommy_tree *tree, const void *data)
Searches an element in the tree with key less or equal than the specified one.
Definition: tommytree.h:683
tommy_tree_node * tommy_tree_find_greater_compare(tommy_tree *tree, tommy_compare_func *cmp, const void *cmp_arg)
Finds the first node in tree order with key strictly greater than the specified one using a specific ...
Definition: tommytree.h:545
tommy_tree_node * tommy_tree_find_less_equal_compare(tommy_tree *tree, tommy_compare_func *cmp, const void *cmp_arg)
Finds a node in the tree with key less or equal than the specified one with a specific comparison fun...
Definition: tommytree.h:622
void * tommy_tree_search_less(tommy_tree *tree, const void *data)
Searches the last element in tree order with key strictly less than the specified one.
Definition: tommytree.h:755
tommy_bool_t tommy_tree_empty(const tommy_tree *tree)
Checks whether the tree is empty.
Definition: tommytree.h:850
void * tommy_tree_search_greater_equal_compare(tommy_tree *tree, tommy_compare_func *cmp, const void *cmp_arg)
Searches an element in the tree with key greater or equal than the specified one with a specific comp...
Definition: tommytree.h:515
TOMMY_API void tommy_tree_foreach_arg(tommy_tree *tree, tommy_foreach_arg_func *func, void *arg)
Calls the specified function with an argument for each element in the tree.
void tommy_foreach_func(void *elem)
Foreach function.
Definition: tommytypes.h:346
int tommy_compare_func(const void *elem_a, const void *elem_b)
Compare function for elements.
Definition: tommytypes.h:302
uint64_t tommy_size_t
Generic size_t type.
Definition: tommytypes.h:40
void tommy_foreach_arg_func(void *arg, void *elem)
Foreach function with an argument.
Definition: tommytypes.h:353
uintptr_t tommy_uintptr_t
Generic uintptr_t type.
Definition: tommytypes.h:36
int tommy_bool_t
Generic boolean type.
Definition: tommytypes.h:53