-
Notifications
You must be signed in to change notification settings - Fork 8
/
rb.h
46 lines (33 loc) · 986 Bytes
/
rb.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
#ifndef RB_HDR
#define RB_HDR
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct rb_node_s rb_node_t;
typedef struct rb_tree_s rb_tree_t;
struct rb_node_s {
uintptr_t parent;
rb_node_t *right;
rb_node_t *left;
};
struct rb_tree_s {
rb_node_t *root;
void *aux;
};
typedef int (*rb_compare_t)(const rb_node_t *lhs, const rb_node_t *rhs, const void *aux);
void rb_init(rb_tree_t *tree, void *aux);
void rb_insert(rb_tree_t *tree, rb_node_t *node, rb_compare_t compare);
void rb_remove(rb_tree_t *tree, rb_node_t *node);
rb_node_t *rb_search(rb_tree_t *tree, rb_node_t *node, rb_compare_t compare);
rb_node_t *rb_head(const rb_tree_t *tree);
rb_node_t *rb_tail(const rb_tree_t *tree);
rb_node_t *rb_next(const rb_node_t *tree);
rb_node_t *rb_prev(const rb_node_t *tree);
#define rb_ref(ELEMENT, TYPE, MEMBER) \
((TYPE *)((unsigned char *)(ELEMENT) - offsetof(TYPE, MEMBER)))
#ifdef __cplusplus
}
#endif
#endif