-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxtree.h
executable file
·65 lines (52 loc) · 1.43 KB
/
xtree.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
/**
* @file xtree.h
* @author Hightman Mar
* @editor set number ; syntax on ; set autoindent ; set tabstop=4 (vim)
* $Id$
*/
#ifndef _SCWS_XTREE_20070525_H_
#define _SCWS_XTREE_20070525_H_
#ifdef __cplusplus
extern "C" {
#endif
/* pool required */
#include "pool.h"
/* data structure for Hash+Tree */
typedef struct tree_node node_st, *node_t;
struct tree_node
{
char *key;
void *value;
int vlen;
node_t left;
node_t right;
};
typedef struct
{
pool_t p; /* pool for memory manager */
int base; /* base number for hasher (prime number recommend) */
int prime; /* good prime number for hasher */
int count; /* total nodes */
node_t *trees; /* trees [total=prime+1] */
} xtree_st, *xtree_t;
/* xtree: api */
int xtree_hasher(xtree_t xt, const char *key, int len);
xtree_t xtree_new(int base, int prime); /* create a new hasxtree */
void xtree_free(xtree_t xt); /* delete & free xthe xtree */
void xtree_put(xtree_t xt, const char *value, const char *key);
void xtree_nput(xtree_t xt, void *value, int vlen, const char *key, int len);
void *xtree_get(xtree_t xt, const char *key, int *vlen);
void *xtree_nget(xtree_t xt, const char *key, int len, int *vlen);
/*
void xtree_del(xtree_t xt, const char *key);
void xtree_ndel(xtree_t xt, const char *key, int len);
*/
#ifdef DEBUG
void xtree_draw(xtree_t xt);
#endif
void xtree_optimize(xtree_t xt);
void xtree_to_xdb(xtree_t xt, const char *fpath);
#ifdef __cplusplus
}
#endif
#endif