-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathradixdb.h
72 lines (56 loc) · 1.87 KB
/
radixdb.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
/* This file is a part of radixdb package by G. B. Versiani, [email protected].
* Public domain.
*/
#ifndef RADIXDB_H
#define RADIXDB_H
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#define RADIXDB_MAX_KEY_LENGTH 0x0ffffffful
struct radixdb {
unsigned char* mem; /* used memory */
uint32_t dend; /* end of data ptr */
};
void radixdb_free(struct radixdb* tp);
/* Check if the RadixDB structure is valid (i.e. if the loaded database is not
* corrupted). This is a O(n) operation.
*/
int radixdb_check(struct radixdb* tp);
int radixdb_lookup(const struct radixdb* tp,
const char *key, size_t klen,
const char **val, size_t *vlen);
int radixdb_longest_match(const struct radixdb* tp,
const char *key, size_t klen,
const char **keymatch, size_t *matchlen,
const char **val, size_t *vlen);
/* Simple data iterator. Returns key-values in the order they were added. The
* iterator parameter must be initialized with 4.
*/
int radixdb_iter_next(const struct radixdb* tp,
uint32_t *iterator,
const char **key, size_t *klen,
const char **val, size_t *vlen);
/* radixdb_make */
struct radixdb_node {
int b;
char *key, *val;
size_t klen, vlen;
struct radixdb_node *left, *right;
};
struct radixdb_make {
struct radixdb_node head;
unsigned char* mem; /* used memory */
uint32_t size; /* memory size */
uint32_t dend; /* end of data ptr */
};
int radixdb_make_start(struct radixdb_make* tpm);
int radixdb_make_add(struct radixdb_make* tpm,
const char *key, size_t klen,
const char *val, size_t vlen);
int radixdb_make_finish(struct radixdb_make *tpm, struct radixdb* tp);
#ifdef __cplusplus
}
#endif
#endif