view src/btree_mem.h @ 20:66aecb6a0057

making progress
author Eris Caffee <discordia@eldalin.com>
date Thu, 18 Oct 2012 20:08:51 -0500
parents 0bf94d0ed0b0
children 36018adade6d
line source
1 #ifndef BTREE_MEM_H_
2 #define BTREE_MEM_H_
5 #define DEBUG
8 struct btree_mem_node;
9 struct btree_mem;
11 // Constructor and destructor
12 // When calling btree_mem_new, the min_degree should be the minimum degree of the B-Tree (using Cormen et al's terminology)
13 // and the cmp function should take pointers to two keys a and b and return -1 if a<b, 0 if a==b, and 1 if a>b
14 struct btree_mem * btree_mem_new (int min_degree, int (*cmp)(void *, void *));
15 void btree_mem_delete (struct btree_mem * bt);
17 void * btree_mem_insert (struct btree_mem * bt, void * key, void * data);
18 void * btree_mem_find (struct btree_mem * bt, void * key);
19 void * btree_mem_remove (struct btree_mem * bt, void * key, void ** key_value, void ** data_value);
21 // Walk the tree in key order, starting with the lowest, and apply the function f to each one. The argumemnts to f are
22 // int depth in the tree, the pointer to the key, and the pointer to the data. Note that the key cannot be modified,
23 // but the data can. Be careful with that. You are given a pointer to the data, not a pointer to the pointer.
24 // In other words, as long as your manipulation of the data does not change it's address, or the size of the data
25 // memory block, then you should be safe. If you need to actually replace the data entirely, though, you should
26 // remove and insert.
27 void btree_mem_walk_inorder (struct btree_mem * bt, void (*f)(int, void const * const, void * const));
29 #ifdef DEBUG
30 // btree_mem_dump takes a pointer to a function that prints a represenation of the keya nd data to the stdout.
31 void btree_mem_dump (struct btree_mem * bt, void (*f)(int, void const * const, void * const));
32 #endif
34 #endif