-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcritbit.h
60 lines (48 loc) · 2.16 KB
/
critbit.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
/*
Copyright (c) 2012, Enno Rehling <[email protected]>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**/
#ifndef _CRITBITT_H
#define _CRITBITT_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stddef.h>
typedef struct critbit_tree {
void * root;
} critbit_tree;
#define CB_SUCCESS 0
#define CB_EXISTS 1
#define CB_NOTFOUND 2
#define CRITBIT_TREE() { 0 }
int cb_insert(critbit_tree * cb, const void * key, size_t keylen);
const void * cb_find(critbit_tree * cb, const void * key, size_t keylen);
int cb_erase(critbit_tree * cb, const void * key, size_t keylen);
int cb_find_prefix(const critbit_tree * cb, const void * key, size_t keylen, void ** results, int numresults, int offset);
int cb_foreach(critbit_tree * cb, const void * key, size_t keylen, int (*match_cb)(const void * match, const void * key, size_t keylen, void *), void *data);
void cb_clear(critbit_tree * cb);
#define cb_insert_str(cb, key) \
cb_insert(cb, (void *)key, strlen(key)+1)
#define cb_find_str(cb, key) \
(const char *)cb_find(cb, (void *)key, strlen(key)+1)
#define cb_erase_str(cb, key) \
cb_erase(cb, (void *)key, strlen(key)+1)
#define cb_find_prefix_str(cb, key, results, numresults, offset) \
cb_find_prefix(cb, (const void *)key, strlen(key), results, numresults, offset)
#define CB_KV_SIZE(keylen, datalen) (keylen+datalen+1)
size_t cb_new_kv(const char *key, size_t keylen, const void * value, size_t len, void * out);
void cb_get_kv(const void *kv, void * value, size_t len);
void cb_get_kv_ex(void *kv, void ** value);
#ifdef __cplusplus
}
#endif
#endif