Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_trees.h
Go to the documentation of this file.
1
8#ifndef __NILOREA_TREES__
9#define __NILOREA_TREES__
10
11#ifdef __cplusplus
12extern "C"
13{
14#endif
15
16#include "nilorea/n_common.h"
17#include "nilorea/n_str.h"
18#include "nilorea/n_log.h"
19#include "nilorea/n_list.h"
20#include "nilorea/n_hash.h"
21#include "nilorea/n_3d.h"
22
30 {
32 int ival ;
34 double fval ;
36 void *ptr ;
38 char *string ;
41 };
42
44 typedef struct NODE_DATA
45 {
49 int32_t type ;
50 } NODE_DATA;
51
53 typedef struct TREE_NODE
54 {
58 void (*destroy_func)( void *ptr );
65 } TREE_NODE ;
66
68 typedef struct TREE
69 {
73 pthread_rwlock_t rwlock;
75 size_t nb_nodes ;
77 size_t height ;
78 } TREE ;
79
80 // create a TREE
81 TREE *new_tree();
82 // create a TREE node
83 TREE_NODE* tree_create_node( NODE_DATA value, void (*destroy_func)( void *ptr ));
84 // insert a node in the parent node
85 int tree_insert_child(TREE_NODE *parent, TREE_NODE *child);
86 // delete a TREE node
87 int tree_delete_node(TREE *tree, TREE_NODE *node);
88 // delete a TREE
89 void tree_destroy(TREE **tree);
90
93 COORD_INT,
94 COORD_FLOAT,
95 COORD_DOUBLE
96 };
97
99 typedef union {
100 int i;
101 float f;
102 double d;
103 } COORD_VALUE;
104
106 typedef struct POINT2D {
112 } POINT2D;
113
115 typedef struct POINT3D {
123 } POINT3D;
124
128 typedef void (*print_func)(COORD_VALUE val);
129
149
161
162 // Function to create a new quad tree
163 QUADTREE* create_quadtree(int coord_type);
164 // Function to create a new quad tree node
165 QUADTREE_NODE* create_node(COORD_VALUE x, COORD_VALUE y, void *data_ptr);
166 // Function to search for a point in the quad tree
168 // Function to insert a point into the quad tree
169 void insert(QUADTREE *qt, QUADTREE_NODE **root, COORD_VALUE x, COORD_VALUE y, void *data_ptr);
170 // Function to free the quad tree
171 void free_quadtree(QUADTREE_NODE *root);
172
174 typedef struct OCTREE_NODE {
178 void *data_ptr;
181 } OCTREE_NODE;
182
184 typedef struct {
189 } OCTREE;
190
191 // Function prototypes
192 OCTREE* create_octree(int type);
193 OCTREE_NODE* create_octree_node(POINT3D point, void *data_ptr);
194 void insert_octree(OCTREE *OCTREE, POINT3D point, void *data_ptr);
195 void free_octree_node(OCTREE_NODE *node);
197
198#ifdef __cplusplus
199}
200#endif
201
206#endif // header guard
207
Structure of a generic LIST container.
Definition n_list.h:45
Structure of a generic list node.
Definition n_list.h:27
A box including a string and his lenght.
Definition n_str.h:173
POINT2D point
X,Y point.
Definition n_trees.h:137
print_func print
pointer to print function
Definition n_trees.h:157
compare_func compare
pointer to comparison function
Definition n_trees.h:155
TREE_NODE * root
pointer to first node
Definition n_trees.h:71
pthread_rwlock_t rwlock
mutex for thread safety (optional)
Definition n_trees.h:73
struct QUADTREE_NODE * nw
North-West child.
Definition n_trees.h:141
char * string
char *type
Definition n_trees.h:38
int coord_type
type of coordinate used in the quad tree
Definition n_trees.h:153
size_t nb_nodes
number of nodes in the tree
Definition n_trees.h:75
COORD_VALUE z
z coordinate
Definition n_trees.h:122
void * data_ptr
Pointer to additional data, can be NULL.
Definition n_trees.h:178
OCTREE_NODE * root
tree list first node
Definition n_trees.h:186
COORD_VALUE y
Y coordinate.
Definition n_trees.h:135
QUADTREE_NODE * root
tree list first node
Definition n_trees.h:159
union NODE_DATA_TYPES value
node value
Definition n_trees.h:47
COORD_VALUE x
x coordinate
Definition n_trees.h:109
int32_t type
node type
Definition n_trees.h:49
NODE_DATA data
structure holding values for node
Definition n_trees.h:56
struct QUADTREE_NODE * sw
South-West child.
Definition n_trees.h:145
COORD_VALUE x
x coordinate
Definition n_trees.h:118
COORD_VALUE y
y coordinate
Definition n_trees.h:111
double fval
double type
Definition n_trees.h:34
void * ptr
pointer type
Definition n_trees.h:36
void * data_ptr
Pointer to data, can be NULL.
Definition n_trees.h:139
struct QUADTREE_NODE * se
South-East child.
Definition n_trees.h:147
POINT3D point
Point represented by this node.
Definition n_trees.h:176
struct QUADTREE_NODE * ne
North-East child.
Definition n_trees.h:143
void(* destroy_func)(void *ptr)
value destructor if of type ptr and specified, else a simple free will be used
Definition n_trees.h:58
int ival
integral type
Definition n_trees.h:32
COORD_VALUE y
y coordinate
Definition n_trees.h:120
COORD_VALUE x
X coordinate.
Definition n_trees.h:133
struct OCTREE_NODE * children[8]
Child nodes.
Definition n_trees.h:180
LIST_NODE * parent_list_node
pointer to parent container of the TREE_NODE, LIST_NODE
Definition n_trees.h:62
N_STR * nstr
N_STR *type.
Definition n_trees.h:40
struct TREE_NODE * parent
pointer to parent
Definition n_trees.h:60
size_t height
height of the tree
Definition n_trees.h:77
LIST * children
ordered list of children
Definition n_trees.h:64
int coord_type
Coordinate type for the entire tree.
Definition n_trees.h:188
int(* compare_func)(COORD_VALUE a, COORD_VALUE b)
function pointer types for comparison
Definition n_trees.h:126
void free_octree_node(OCTREE_NODE *node)
recursive function to free an OCTREE node and its children
Definition n_trees.c:406
void insert_octree(OCTREE *OCTREE, POINT3D point, void *data_ptr)
Insert a point into the OCTREE.
Definition n_trees.c:394
int tree_insert_child(TREE_NODE *parent, TREE_NODE *child)
insert a child node into the parent node
Definition n_trees.c:62
void free_quadtree(QUADTREE_NODE *root)
Function to free the quad tree.
Definition n_trees.c:304
TREE * new_tree()
create a new TREE
Definition n_trees.c:21
TREE_NODE * tree_create_node(NODE_DATA value, void(*destroy_func)(void *ptr))
create a TREE node
Definition n_trees.c:40
void(* print_func)(COORD_VALUE val)
function pointer types for debug print
Definition n_trees.h:128
QUADTREE_NODE * search(QUADTREE *qt, QUADTREE_NODE *root, COORD_VALUE x, COORD_VALUE y)
Function to search for a point in the quad tree.
Definition n_trees.c:282
COORD_TYPE
Enum for coordinate types.
Definition n_trees.h:92
void free_octree(OCTREE *OCTREE)
free the OCTREE
Definition n_trees.c:419
void tree_destroy(TREE **tree)
destroy a TREE
Definition n_trees.c:131
OCTREE_NODE * create_octree_node(POINT3D point, void *data_ptr)
create and OCTREE node
Definition n_trees.c:321
OCTREE * create_octree(int type)
Create a new OCTREE with a specified coordinate type.
Definition n_trees.c:338
int tree_delete_node(TREE *tree, TREE_NODE *node)
delete a TREE node
Definition n_trees.c:95
void insert(QUADTREE *qt, QUADTREE_NODE **root, COORD_VALUE x, COORD_VALUE y, void *data_ptr)
Function to insert a point into the quad tree.
Definition n_trees.c:257
QUADTREE * create_quadtree(int coord_type)
Function to create a new quad tree.
Definition n_trees.c:207
QUADTREE_NODE * create_node(COORD_VALUE x, COORD_VALUE y, void *data_ptr)
function to create a new quad tree node
Definition n_trees.c:237
structure of a TREE node data
Definition n_trees.h:45
structure of an OCTREE
Definition n_trees.h:184
structure of an OCTREE node
Definition n_trees.h:174
Structure for a POINT2D in the 2D space.
Definition n_trees.h:106
Structure for a POINT3D in the 3D space.
Definition n_trees.h:115
structure of a quad tree
Definition n_trees.h:151
structure of a quad tree node
Definition n_trees.h:131
structure of a TREE
Definition n_trees.h:69
structure of a n-ary TREE node
Definition n_trees.h:54
Union to store the coordinate values.
Definition n_trees.h:99
union of the possibles data values of a TREE node
Definition n_trees.h:30
Simple 3D movement simulation.
Common headers and low-level hugly functions & define.
Hash functions and table.
List structures and definitions.
Generic log system.
N_STR and string function declaration.