MGE General C Library - API Documentation  v1.8.4
Library of general C functions.
mge-bstree.h
Go to the documentation of this file.
1 
16 #ifndef MGE_BSTREE_H
17 #define MGE_BSTREE_H
18 
20 
21 #include <stddef.h>
22 
24 
25 #define BST_NODES_UNIQUE 1
26 #define BST_NODES_DUPLICATES 0
29 struct bstreenode {
30  void *object;
31  int count;
38 };
39 
41 struct bstree {
42  struct bstreenode *root;
43  int unique;
46  int node_total;
47  int (*comp)(const void *, const void *);
51 };
52 
53 struct bstree *cre_bst(int unique, int (*comp)(const void *, const void *));
54 
55 struct bstree *add_bst_node(struct bstree *tree, const void *object,
56  size_t objsize);
57 
58 void *find_bst_node(const struct bstree *tree, const void *searchobj);
59 
60 int get_counter_bst_node(const struct bstree *tree, const void *searchobj);
61 
62 void *find_next_bst_node(const struct bstree *tree, const void *searchobj);
63 
64 void *find_prev_bst_node(const struct bstree *tree, const void *searchobj);
65 
66 void *upd_bst_node(const struct bstree *tree, const void *updobj,
67  size_t objsize);
68 
69 struct bstree *del_bst_node(struct bstree *tree, const void *searchobj);
70 
71 struct bstree *del_bst(struct bstree *tree);
72 
74 
75 #endif /* ndef MGE_BSTREE_H */
Binary search tree.
Definition: mge-bstree.h:41
struct bstree * del_bst(struct bstree *tree)
Delete a bst.
Definition: bstree.c:703
struct bstree * del_bst_node(struct bstree *tree, const void *searchobj)
Delete a node.
Definition: bstree.c:580
int(* comp)(const void *, const void *)
Comparison function.
Definition: mge-bstree.h:47
void * object
The object attached to the node.
Definition: mge-bstree.h:30
int node_total
Number of nodes in the tree.
Definition: mge-bstree.h:46
int unique
Uniqueness of nodes.
Definition: mge-bstree.h:43
Header file to ease portability.
#define END_C_DECLS
Use END_C_DECLS at the end of C declarations.
Definition: mge-portability.h:34
void * find_prev_bst_node(const struct bstree *tree, const void *searchobj)
Find the previous node.
Definition: bstree.c:446
void * find_bst_node(const struct bstree *tree, const void *searchobj)
Find an exact object match.
Definition: bstree.c:260
struct bstreenode * childgreater
Child node greater than this node.
Definition: mge-bstree.h:36
int count_total
Sum of all node counters.
Definition: mge-bstree.h:45
struct bstreenode * childless
Child node less than this node.
Definition: mge-bstree.h:35
#define BEGIN_C_DECLS
BEGIN_C_DECLS should be used at the beginning of declarations so that C++ compilers don&#39;t mangle thei...
Definition: mge-portability.h:30
void * upd_bst_node(const struct bstree *tree, const void *updobj, size_t objsize)
Update a node&#39;s object.
Definition: bstree.c:511
Binary search tree node.
Definition: mge-bstree.h:29
struct bstree * add_bst_node(struct bstree *tree, const void *object, size_t objsize)
Add a node to a binary search tree.
Definition: bstree.c:138
int get_counter_bst_node(const struct bstree *tree, const void *searchobj)
Get the counter for a node.
Definition: bstree.c:320
void * find_next_bst_node(const struct bstree *tree, const void *searchobj)
Find the next node.
Definition: bstree.c:381
int count
The node counter.
Definition: mge-bstree.h:31
struct bstree * cre_bst(int unique, int(*comp)(const void *, const void *))
Create a binary search tree.
Definition: bstree.c:89
struct bstreenode * root
The root node of the tree.
Definition: mge-bstree.h:42