-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdltree_headers.h
93 lines (60 loc) · 1.91 KB
/
dltree_headers.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
* @file dlbinarytree_headers.h
* @brief Tree prototypes
* @author Dominique LaSalle <[email protected]>
* Copyright (c) 2013-2015, Dominique LaSalle
* @version 1
* @date 2013-10-03
*/
/* this is ugly but neccessary */
#define DLTREE_PRE2(prefix,suffix) prefix ## _ ## suffix
#define DLTREE_PRE1(prefix,suffix) DLTREE_PRE2(prefix,suffix)
#define DLTREE_PUB(name) DLTREE_PRE1(DLTREE_PREFIX,name)
#define DLTREE_PRI(name) \
DLTREE_PRE1(_,DLTREE_PRE1(DLTREE_PREFIX,name))
#ifndef DLTREE_WIDTH
#define DLTREE_WIDTH 5
#endif
/******************************************************************************
* TYPES ***********************************************************************
******************************************************************************/
typedef struct DLTREE_PRI(tree_node_t) {
DLTREE_KEY_T key[DLTREE_WIDTH];
DLTREE_VAL_T val[DLTREE_WIDTH];
struct DLTREE_PRI(tree_node_t) * children[DLTREE_WIDTH+1];
size_t nelements;
size_t nchildren;
} DLTREE_PRI(tree_node_t);
typedef struct DLTREE_PUB(tree_t) {
DLTREE_PRI(tree_node_t) * root;
size_t size;
int (*compar)(DLTREE_KEY_T const, DLTREE_KEY_T const);
} DLTREE_PUB(tree_t);
#ifndef DLTREE_STATIC
DLTREE_PUB(tree_t) * DLTREE_PUB(tree_create)(
int (*compar)(DLTREE_KEY_T const, DLTREE_KEY_T const));
void DLTREE_PUB(tree_free)(
DLTREE_PUB(tree_t) * tree);
int DLTREE_PUB(tree_add)(
DLTREE_KEY_T const key,
DLTREE_VAL_T const val,
DLTREE_PUB(tree_t) * tree);
DLTREE_VAL_T DLTREE_PUB(tree_remove)(
DLTREE_KEY_T const key,
DLTREE_PUB(tree_t) * tree);
DLTREE_VAL_T DLTREE_PUB(tree_get)(
DLTREE_KEY_T const key,
DLTREE_PUB(tree_t) * tree);
#undef DLTREE_PUB
#undef DLTREE_PRI
#undef DLTREE_PRE1
#undef DLTREE_PRE2
#else
#undef DLTREE_PUB
#undef DLTREE_PRI
#undef DLTREE_PRE1
#undef DLTREE_PRE2
#define DLTREE_VISIBILITY static
#include "dltree_funcs.h"
#undef DLTREE_VISIBILITY
#endif