Go to the source code of this file.
Data Structures |
struct | btree_node |
struct | btree |
Defines |
#define | btree_maxnodes 8 |
#define | btree_minnodes 4 |
#define | btree_cache 256 |
#define | btree_err_ok 0 |
#define | btree_err_null -1 |
#define | btree_err_malloc -2 |
#define | btree_err_map -3 |
#define | btree_flag_freeable 1 |
#define | btree_flag_leaf 2 |
#define | btree_maptype int (*)( void * , void * ) |
Functions |
int | btree_init (struct btree *b) |
| Initialize the given btree.
|
struct btree_node * | btree_getnode (struct btree *b) |
| get a btree_node from the btree's cache.
|
int | btree_insert (struct btree *b, int key, void *data) |
| Insert a key/data pair into the given btree.
|
int | btree_map (struct btree *b, int(*func)(void *, void *), void *data) |
| Apply a given function to all data in a btree.
|
int | btree_dump (struct btree *b, FILE *out) |
| Dump the given btree.
|
int | btree_find (struct btree *b, int key, void **res) |
| Retrieve the data for a given key.
|
int | btree_releasenode (struct btree *b, struct btree_node *n) |
| Return a btree_node to the btree's cache.
|
int | btree_delete (struct btree *b, int key, void **res) |
| Delete a key from the btree.
|
struct btree * | btree_new () |
int | btree_flush (struct btree *b) |
int | btree_count (struct btree *b) |
Variables |
int | btree_err |
Define Documentation
Define type for mapping function
Function Documentation
Delete a key from the btree.
- Parameters:
-
b | the btree. |
key | the key to search for and remove |
res | a pointer to a pointer in which the address of the data will be written, if found (may be NULL ) |
- Returns:
- 1 if the
key
was found, 0 if not and < 0 on error (see btree_err).
Dump the given btree.
- Parameters:
-
b | the btree. |
out | a pointer to the FILE in which to dump the btree. |
Retrieve the data for a given key.
- Parameters:
-
b | the btree in which to search. |
key | the key to search for. |
res | a pointer to a pointer in which the address of the data will be written. |
- Returns:
- 1 if found, 0 if not and < 0 on err (see btree_err).
Looks for the given key
and copies its data pointer to the address given by res
.
Insert a key/data pair into the given btree.
- Parameters:
-
b | the btree. |
key | the integer key. |
data | a pointer to the data associated with key . |
- Returns:
- btree_err_ok or < 0 on error (see btree_err).
If a node with the given key already exists, the data pointer is replaced.
int btree_map |
( |
struct btree * |
b, |
|
|
int(*)(void *, void *) |
func, |
|
|
void * |
data |
|
) |
| |
Apply a given function to all data in a btree.
- Parameters:
-
b | the btree. |
func | the funciton, which should be of the type btree_maptype. |
data | a pointer that will be passed to func with each call. |
- Returns:
- btree_err_ok or < 0 on error (see btree_err).
If func
returns < 0 for any node, the traversal is interrupted and an error is returned.
Variable Documentation
ID of the last error
ID of the last error.