1 |
adcroft |
1.1 |
/* */ |
2 |
|
|
|
3 |
|
|
|
4 |
|
|
typedef struct BTREE_Page |
5 |
|
|
{ |
6 |
|
|
unsigned long next; /* Next Page */ |
7 |
|
|
unsigned long prev; /* Previous Page */ |
8 |
|
|
unsigned int size; /* Size of page */ |
9 |
|
|
unsigned int n; /* Number of keys in page */ |
10 |
|
|
unsigned int flags; |
11 |
|
|
unsigned int data_end; |
12 |
|
|
|
13 |
|
|
unsigned long page_number; |
14 |
|
|
int modified; |
15 |
|
|
int in_use; |
16 |
|
|
|
17 |
|
|
struct BTREE_Page *next_cache; |
18 |
|
|
|
19 |
|
|
unsigned char data[0]; /* Page data */ |
20 |
|
|
} BTREE_Page; |
21 |
|
|
|
22 |
|
|
#define BTREE_CACHE_SIZE 97 |
23 |
|
|
|
24 |
|
|
typedef struct BTREE |
25 |
|
|
{ |
26 |
|
|
unsigned long root_page; |
27 |
|
|
int page_size; |
28 |
|
|
struct BTREE_Page *cache[BTREE_CACHE_SIZE]; |
29 |
|
|
int levels; |
30 |
|
|
unsigned long tree[1024]; |
31 |
|
|
/* Values for sequential reading */ |
32 |
|
|
unsigned long current_page; |
33 |
|
|
unsigned long current_position; |
34 |
|
|
|
35 |
|
|
FILE *fp; |
36 |
|
|
} BTREE; |
37 |
|
|
|
38 |
|
|
BTREE *BTREE_Create(FILE *fp, unsigned int size); |
39 |
|
|
BTREE *BTREE_Open(FILE *fp, int size, unsigned long root_page); |
40 |
|
|
unsigned long BTREE_Close(BTREE *bt); |
41 |
|
|
int BTREE_Insert(BTREE *b, unsigned char *key, int key_len, unsigned long data_pointer); |
42 |
|
|
long BTREE_Search(BTREE *b, unsigned char *key, int key_len, unsigned char **found, int *found_len, int exact_match); |
43 |
|
|
long BTREE_Next(BTREE *b, unsigned char **found, int *found_len); |
44 |
|
|
int BTREE_Update(BTREE *b, unsigned char *key, int key_len, unsigned long new_data_pointer); |
45 |
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
|