mdcore  0.1.5
Data Structures | Defines | Functions | Variables
/home/pedro/work/mdcore/src/btree.h File Reference

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_nodebtree_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 btreebtree_new ()
int btree_flush (struct btree *b)
int btree_count (struct btree *b)

Variables

int btree_err

Define Documentation

#define btree_cache   256
#define btree_err_malloc   -2
#define btree_err_map   -3
#define btree_err_null   -1
#define btree_err_ok   0

Error constants.

#define btree_flag_freeable   1

Flags.

#define btree_flag_leaf   2
#define btree_maptype   int (*)( void * , void * )

Define type for mapping function

#define btree_maxnodes   8

BTree constants.

#define btree_minnodes   4

Function Documentation

int btree_count ( struct btree b)
int btree_delete ( struct btree b,
int  key,
void **  res 
)

Delete a key from the btree.

Parameters:
bthe btree.
keythe key to search for and remove
resa 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).
int btree_dump ( struct btree b,
FILE *  out 
)

Dump the given btree.

Parameters:
bthe btree.
outa pointer to the FILE in which to dump the btree.
int btree_find ( struct btree b,
int  key,
void **  res 
)

Retrieve the data for a given key.

Parameters:
bthe btree in which to search.
keythe key to search for.
resa 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.

int btree_flush ( struct btree b)
struct btree_node* btree_getnode ( struct btree b) [read]

get a btree_node from the btree's cache.

Parameters:
thebtree.
Returns:
A pointer to a btree_node or NULL if an error occured (see btree_err).
int btree_init ( struct btree b)

Initialize the given btree.

Parameters:
bthe btree.
Returns:
btree_err_ok or < 0 on error.
int btree_insert ( struct btree b,
int  key,
void *  data 
)

Insert a key/data pair into the given btree.

Parameters:
bthe btree.
keythe integer key.
dataa 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:
bthe btree.
functhe funciton, which should be of the type btree_maptype.
dataa 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.

struct btree* btree_new ( ) [read]
int btree_releasenode ( struct btree b,
struct btree_node n 
)

Return a btree_node to the btree's cache.

Parameters:
bthe btree.
nthe btree_node
Returns:
A pointer to a btree_node or NULL if an error occured (see btree_err).

Variable Documentation

int btree_err

ID of the last error

ID of the last error.

 All Data Structures Files Functions Variables Typedefs Enumerator Defines