bpp_tree.h
Go to the documentation of this file.
1 /******************************************************************************/
34 /******************************************************************************/
35 
36 #if !defined(BPP_TREE_H_)
37 #define BPP_TREE_H_
38 
39 #if defined(__cplusplus)
40 extern "C" {
41 #endif
42 
43 #include <stdio.h>
44 #include <stdlib.h>
45 #include <stdarg.h>
46 #include <string.h>
47 #include <stdint.h>
48 #include "../../key_value/kv_system.h"
49 #include "./../dictionary.h"
50 #include "./../../file/ion_file.h"
51 
52 /****************************
53  * implementation dependent *
54  ****************************/
55 typedef long ion_bpp_external_address_t; /* record address for external record */
56 typedef long ion_bpp_address_t; /* record address for btree node */
57 
58 #define ION_CC_EQ 0
59 #define ION_CC_GT 1
60 #define ION_CC_LT -1
61 
62 /* compare two keys and return:
63  * CC_LT key1 < key2
64  * CC_GT key1 > key2
65  * CC_EQ key1 = key2
66 */
67 typedef char (*ion_bpp_comparison_t)(
68  ion_key_t key1,
69  ion_key_t key2,
70  ion_key_size_t size
71 );
72 
73 /* typedef int (*ion_bpp_comparison_t)(const void *key1, const void *key2, unsigned int size); */
74 
75 /******************************
76  * implementation independent *
77  ******************************/
78 
80 
81 /* typedef enum {false, true} bool; */
82 typedef enum ION_BPP_ERR {
85 
86 typedef void *ion_bpp_handle_t;
87 
88 typedef struct {
89  /* info for bOpen() */
90  char *iName; /* name of index file */
91  int keySize;/* length, in bytes, of key */
92  ion_bpp_bool_t dupKeys; /* true if duplicate keys allowed */
93  size_t sectorSize; /* size of sector on disk */
94  ion_bpp_comparison_t comp; /* pointer to compare function */
96 
97 /***********************
98  * function prototypes *
99  ***********************/
100 ion_bpp_err_t
101 b_open(
102  ion_bpp_open_t info,
103  ion_bpp_handle_t *handle
104 );
105 
106 /*
107  * input:
108  * info info for open
109  * output:
110  * handle handle to btree, used in subsequent calls
111  * returns:
112  * bErrOk open was successful
113  * bErrMemory insufficient memory
114  * bErrSectorSize sector size too small or not 0 mod 4
115  * bErrFileNotOpen unable to open index file
116 */
117 
118 ion_bpp_err_t
119 b_close(
120  ion_bpp_handle_t handle
121 );
122 
123 /*
124  * input:
125  * handle handle returned by bOpen
126  * returns:
127  * bErrOk file closed, resources deleted
128 */
129 
130 ion_bpp_err_t
131 b_insert(
132  ion_bpp_handle_t handle,
133  void *key,
134  ion_bpp_external_address_t rec
135 );
136 
137 /*
138  * input:
139  * handle handle returned by bOpen
140  * key key to insert
141  * rec record address
142  * returns:
143  * bErrOk operation successful
144  * bErrDupKeys duplicate keys (and info.dupKeys = false)
145  * notes:
146  * If dupKeys is false, then all records inserted must have a
147  * unique key. If dupkeys is true, then duplicate keys are
148  * allowed, but they must all have unique record addresses.
149  * In this case, record addresses are included in internal
150  * nodes to generate a "unique" key.
151 */
152 
153 ion_bpp_err_t
154 b_update(
155  ion_bpp_handle_t handle,
156  void *key,
157  ion_bpp_external_address_t rec
158 );
159 
160 /*
161  * input:
162  * handle handle returned by bOpen
163  * key key to update
164  * rec record address
165  * returns:
166  * bErrOk operation successful
167  * bErrDupKeys duplicate keys (and info.dupKeys = false)
168  * notes:
169  * If dupKeys is false, then all records updated must have a
170  * unique key. If dupkeys is true, then duplicate keys are
171  * allowed, but they must all have unique record addresses.
172  * In this case, record addresses are included in internal
173  * nodes to generate a "unique" key.
174 */
175 
176 ion_bpp_err_t
177 b_delete(
178  ion_bpp_handle_t handle,
179  void *key,
180  ion_bpp_external_address_t *rec
181 );
182 
183 /*
184  * input:
185  * handle handle returned by bOpen
186  * key key to delete
187  * rec record address of key to delete
188  * output:
189  * rec record address deleted
190  * returns:
191  * bErrOk operation successful
192  * bErrKeyNotFound key not found
193  * notes:
194  * If dupKeys is false, all keys are unique, and rec is not used
195  * to determine which key to delete. If dupKeys is true, then
196  * rec is used to determine which key to delete.
197 */
198 
199 ion_bpp_err_t
200 b_get(
201  ion_bpp_handle_t handle,
202  void *key,
203  ion_bpp_external_address_t *rec
204 );
205 
206 /*
207  * input:
208  * handle handle returned by bOpen
209  * key key to find
210  * output:
211  * rec record address
212  * returns:
213  * bErrOk operation successful
214  * bErrKeyNotFound key not found
215 */
216 
217 ion_bpp_err_t
219  ion_bpp_handle_t handle,
220  void *key,
221  void *mkey,
222  ion_bpp_external_address_t *rec
223 );
224 
225 /*
226  * input:
227  * handle handle returned by bOpen
228  * key key to find
229  * output:
230  * mkey key associated with the found offset
231  * rec record address of least element greater than or equal to
232  * returns:
233  * bErrOk operation successful
234 */
235 
236 ion_bpp_err_t
238  ion_bpp_handle_t handle,
239  void *key,
240  ion_bpp_external_address_t *rec
241 );
242 
243 /*
244  * input:
245  * handle handle returned by bOpen
246  * output:
247  * key first key in sequential set
248  * rec record address
249  * returns:
250  * bErrOk operation successful
251  * bErrKeyNotFound key not found
252 */
253 
254 ion_bpp_err_t
256  ion_bpp_handle_t handle,
257  void *key,
258  ion_bpp_external_address_t *rec
259 );
260 
261 /*
262  * input:
263  * handle handle returned by bOpen
264  * output:
265  * key last key in sequential set
266  * rec record address
267  * returns:
268  * bErrOk operation successful
269  * bErrKeyNotFound key not found
270 */
271 
272 ion_bpp_err_t
274  ion_bpp_handle_t handle,
275  void *key,
276  ion_bpp_external_address_t *rec
277 );
278 
279 /*
280  * input:
281  * handle handle returned by bOpen
282  * output:
283  * key key found
284  * rec record address
285  * returns:
286  * bErrOk operation successful
287  * bErrKeyNotFound key not found
288 */
289 
290 #if defined(__cplusplus)
291 }
292 #endif
293 
294 #endif
ion_bpp_bool_t dupKeys
Definition: bpp_tree.h:92
ion_bpp_err_t b_insert(ion_bpp_handle_t handle, void *key, ion_bpp_external_address_t rec)
Definition: bpp_tree.c:1167
enum ION_BPP_ERR ion_bpp_err_t
ion_boolean_e ion_bpp_bool_t
Definition: bpp_tree.h:79
ion_bpp_err_t b_find_first_greater_or_equal(ion_bpp_handle_t handle, void *key, void *mkey, ion_bpp_external_address_t *rec)
Definition: bpp_tree.c:1116
ion_bpp_err_t b_find_next_key(ion_bpp_handle_t handle, void *key, ion_bpp_external_address_t *rec)
Definition: bpp_tree.c:1669
ion_bpp_err_t b_find_last_key(ion_bpp_handle_t handle, void *key, ion_bpp_external_address_t *rec)
Definition: bpp_tree.c:1639
#define key(k)
Definition: bpp_tree.c:75
size_t sectorSize
Definition: bpp_tree.h:93
ion_bpp_err_t b_open(ion_bpp_open_t info, ion_bpp_handle_t *handle)
Definition: bpp_tree.c:899
long ion_bpp_address_t
Definition: bpp_tree.h:56
void * ion_key_t
A dictionary key.
Definition: kv_system.h:241
ion_bpp_err_t b_get(ion_bpp_handle_t handle, void *key, ion_bpp_external_address_t *rec)
Definition: bpp_tree.c:1074
char(* ion_bpp_comparison_t)(ion_key_t key1, ion_key_t key2, ion_key_size_t size)
Definition: bpp_tree.h:67
ion_bpp_comparison_t comp
Definition: bpp_tree.h:94
long ion_bpp_external_address_t
Definition: bpp_tree.h:55
void * ion_bpp_handle_t
Definition: bpp_tree.h:86
ion_bpp_err_t b_delete(ion_bpp_handle_t handle, void *key, ion_bpp_external_address_t *rec)
Definition: bpp_tree.c:1453
#define rec(k)
Definition: bpp_tree.c:76
ion_bpp_err_t b_update(ion_bpp_handle_t handle, void *key, ion_bpp_external_address_t rec)
Definition: bpp_tree.c:1345
int ion_key_size_t
The size (length) of a dictionary key in bytes.
Definition: kv_system.h:251
ion_bpp_err_t b_close(ion_bpp_handle_t handle)
Definition: bpp_tree.c:1040
enum ION_BOOLEAN ion_boolean_e
Boolean values.
char * iName
Definition: bpp_tree.h:90
ion_bpp_err_t b_find_first_key(ion_bpp_handle_t handle, void *key, ion_bpp_external_address_t *rec)
Definition: bpp_tree.c:1598
ION_BPP_ERR
Definition: bpp_tree.h:82