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
118typedef struct tommy_tree_struct {
123
129
140TOMMY_API void* tommy_tree_insert(tommy_tree* tree, tommy_tree_node* node, void* data);
141
148TOMMY_API void* tommy_tree_remove(tommy_tree* tree, void* data);
149
156TOMMY_API void* tommy_tree_search(tommy_tree* tree, void* data);
157
167TOMMY_API void* tommy_tree_search_compare(tommy_tree* tree, tommy_compare_func* cmp, void* cmp_arg);
168
175
207
211TOMMY_API 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
Data structure node.
Definition: tommytypes.h:211
Tree container type.
Definition: tommytree.h:118
tommy_tree_node * root
Root node.
Definition: tommytree.h:119
tommy_size_t count
Number of elements.
Definition: tommytree.h:121
tommy_compare_func * cmp
Comparison function.
Definition: tommytree.h:120
TOMMY_API void tommy_tree_foreach(tommy_tree *tree, tommy_foreach_func *func)
Calls the specified function for each element in the tree.
tommy_node tommy_tree_node
Tree node.
Definition: tommytree.h:112
TOMMY_API void * tommy_tree_remove_existing(tommy_tree *tree, tommy_tree_node *node)
Removes an element from the tree.
struct tommy_tree_struct tommy_tree
Tree container type.
TOMMY_API void * tommy_tree_insert(tommy_tree *tree, tommy_tree_node *node, void *data)
Inserts an element in the tree.
tommy_size_t tommy_tree_count(tommy_tree *tree)
Gets the number of elements.
Definition: tommytree.h:216
TOMMY_API 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_API void * tommy_tree_remove(tommy_tree *tree, void *data)
Searches and removes an element.
TOMMY_API tommy_size_t tommy_tree_memory_usage(tommy_tree *tree)
Gets the size of allocated memory.
TOMMY_API void tommy_tree_init(tommy_tree *tree, tommy_compare_func *cmp)
Initializes the tree.
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.
TOMMY_API void * tommy_tree_search(tommy_tree *tree, void *data)
Searches an element in the tree.
Generic types.
int tommy_compare_func(const void *obj_a, const void *obj_b)
Compare function for elements.
Definition: tommytypes.h:269
uint64_t tommy_size_t
Generic size_t type.
Definition: tommytypes.h:60
void tommy_foreach_func(void *obj)
Foreach function.
Definition: tommytypes.h:318
void tommy_foreach_arg_func(void *arg, void *obj)
Foreach function with an argument.
Definition: tommytypes.h:325