tommytree.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, Andrea Mazzoleni. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27 
100 #ifndef __TOMMYTREE_H
101 #define __TOMMYTREE_H
102 
103 #include "tommytypes.h"
104 
105 /******************************************************************************/
106 /* tree */
107 
113 
118 typedef struct tommy_tree_struct {
122 } tommy_tree;
123 
129 
140 void* tommy_tree_insert(tommy_tree* tree, tommy_tree_node* node, void* data);
141 
148 void* tommy_tree_remove(tommy_tree* tree, void* data);
149 
156 void* tommy_tree_search(tommy_tree* tree, void* data);
157 
167 void* tommy_tree_search_compare(tommy_tree* tree, tommy_compare_func* cmp, void* cmp_arg);
168 
175 
207 
211 void tommy_tree_foreach_arg(tommy_tree* tree, tommy_foreach_arg_func* func, void* arg);
212 
217 {
218  return tree->count;
219 }
220 
226 
227 #endif
228 
void tommy_tree_foreach(tommy_tree *tree, tommy_foreach_func *func)
Calls the specified function for each element in the tree.
tommy_count_t tommy_tree_count(tommy_tree *tree)
Gets the number of elements.
Definition: tommytree.h:216
tommy_uint32_t tommy_count_t
Generic unsigned integer for counting objects.
Definition: tommytypes.h:67
tommy_tree_node * root
Root node.
Definition: tommytree.h:119
void * tommy_tree_remove_existing(tommy_tree *tree, tommy_tree_node *node)
Removes an element from the tree.
Tree container type.
Definition: tommytree.h:118
int tommy_compare_func(const void *obj_a, const void *obj_b)
Compare function for elements.
Definition: tommytypes.h:240
tommy_count_t count
Number of elements.
Definition: tommytree.h:121
struct tommy_tree_struct tommy_tree
Tree container type.
void * tommy_tree_search(tommy_tree *tree, void *data)
Searches an element in the tree.
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_tree_search_compare(tommy_tree *tree, tommy_compare_func *cmp, void *cmp_arg)
Searches an element in the tree with a specific comparison function.
tommy_compare_func * cmp
Comparison function.
Definition: tommytree.h:120
void * tommy_tree_insert(tommy_tree *tree, tommy_tree_node *node, void *data)
Inserts an element in the tree.
void * tommy_tree_remove(tommy_tree *tree, void *data)
Searches and removes an element.
Data structure node.
Definition: tommytypes.h:183
void tommy_foreach_func(void *obj)
Foreach function.
Definition: tommytypes.h:289
tommy_node tommy_tree_node
Tree node.
Definition: tommytree.h:112
size_t tommy_size_t
Generic size_t type.
Definition: tommytypes.h:50
void tommy_tree_init(tommy_tree *tree, tommy_compare_func *cmp)
Initializes the tree.
Generic types.
void tommy_foreach_arg_func(void *arg, void *obj)
Foreach function with an argument.
Definition: tommytypes.h:296
tommy_size_t tommy_tree_memory_usage(tommy_tree *tree)
Gets the size of allocated memory.