piojo-0.9
 All Classes Functions Variables Typedefs Enumerations Enumerator Groups
Piojo B-tree

Functions

piojo_btree_t * piojo_btree_alloc_i32k (size_t evsize)
 
piojo_btree_t * piojo_btree_alloc_i64k (size_t evsize)
 
piojo_btree_t * piojo_btree_alloc_sizk (size_t evsize)
 
piojo_btree_t * piojo_btree_alloc_cb_i32k (uint8_t maxchildren, size_t evsize, piojo_alloc_if allocator)
 
piojo_btree_t * piojo_btree_alloc_cb_i64k (uint8_t maxchildren, size_t evsize, piojo_alloc_if allocator)
 
piojo_btree_t * piojo_btree_alloc_cb_sizk (uint8_t maxchildren, size_t evsize, piojo_alloc_if allocator)
 
piojo_btree_t * piojo_btree_alloc_cmp (size_t evsize, piojo_cmp_cb keycmp, size_t eksize)
 
piojo_btree_t * piojo_btree_alloc_cb_cmp (uint8_t maxchildren, size_t evsize, piojo_cmp_cb keycmp, size_t eksize, piojo_alloc_if allocator)
 
piojo_btree_t * piojo_btree_copy (const piojo_btree_t *tree)
 
void piojo_btree_free (const piojo_btree_t *tree)
 
void piojo_btree_clear (piojo_btree_t *tree)
 
size_t piojo_btree_size (const piojo_btree_t *tree)
 
bool piojo_btree_insert (const void *key, const void *data, piojo_btree_t *tree)
 
bool piojo_btree_set (const void *key, const void *data, piojo_btree_t *tree)
 
void * piojo_btree_search (const void *key, const piojo_btree_t *tree)
 
bool piojo_btree_delete (const void *key, piojo_btree_t *tree)
 
const void * piojo_btree_first (const piojo_btree_t *tree, void **data)
 
const void * piojo_btree_last (const piojo_btree_t *tree, void **data)
 
const void * piojo_btree_next (const void *key, const piojo_btree_t *tree, void **data)
 
const void * piojo_btree_prev (const void *key, const piojo_btree_t *tree, void **data)
 

Variables

const size_t piojo_btree_sizeof
 

Detailed Description

Piojo B-tree implementation. Use maxchildren >= 8 for good performance.

Function Documentation

piojo_btree_t* piojo_btree_alloc_cb_cmp ( uint8_t  maxchildren,
size_t  evsize,
piojo_cmp_cb  keycmp,
size_t  eksize,
piojo_alloc_if  allocator 
)

Allocates a new tree.

Parameters
[in]maxchildrenMaximum children in each node (from 4 to 254, and multiple of 2).
[in]evsizeEntry value size in bytes.
[in]keycmpEntry key comparison function.
[in]eksizeEntry key size.
[in]allocatorAllocator to be used.
Returns
New tree.
piojo_btree_t* piojo_btree_alloc_cb_i32k ( uint8_t  maxchildren,
size_t  evsize,
piojo_alloc_if  allocator 
)

Allocates a new tree. Uses key size of int32_t.

Parameters
[in]maxchildrenMaximum children in each node (from 4 to 254, and multiple of 2).
[in]evsizeEntry value size in bytes.
[in]allocatorAllocator to be used.
Returns
New tree.
piojo_btree_t* piojo_btree_alloc_cb_i64k ( uint8_t  maxchildren,
size_t  evsize,
piojo_alloc_if  allocator 
)

Allocates a new tree. Uses key size of int64_t.

Parameters
[in]maxchildrenMaximum children in each node (from 4 to 254, and multiple of 2).
[in]evsizeEntry value size in bytes.
[in]allocatorAllocator to be used.
Returns
New tree.
piojo_btree_t* piojo_btree_alloc_cb_sizk ( uint8_t  maxchildren,
size_t  evsize,
piojo_alloc_if  allocator 
)

Allocates a new tree. Uses key size of size_t.

Parameters
[in]maxchildrenMaximum children in each node (from 4 to 254, and multiple of 2).
[in]evsizeEntry value size in bytes.
[in]allocatorAllocator to be used.
Returns
New tree.
piojo_btree_t* piojo_btree_alloc_cmp ( size_t  evsize,
piojo_cmp_cb  keycmp,
size_t  eksize 
)

Allocates a new tree. Uses default allocator.

Parameters
[in]evsizeEntry value size in bytes.
[in]keycmpEntry key comparison function.
[in]eksizeEntry key size.
Returns
New tree.
piojo_btree_t* piojo_btree_alloc_i32k ( size_t  evsize)

Allocates a new tree. Uses default allocator and key size of int32_t.

Parameters
[in]evsizeEntry value size in bytes.
Returns
New tree.
piojo_btree_t* piojo_btree_alloc_i64k ( size_t  evsize)

Allocates a new tree. Uses default allocator and key size of int64_t.

Parameters
[in]evsizeEntry value size in bytes.
Returns
New tree.
piojo_btree_t* piojo_btree_alloc_sizk ( size_t  evsize)

Allocates a new tree. Uses default allocator and key size of size_t.

Parameters
[in]evsizeEntry value size in bytes.
Returns
New tree.
void piojo_btree_clear ( piojo_btree_t *  tree)

Deletes all entries in tree.

Parameters
[out]treeTree being cleared.
piojo_btree_t* piojo_btree_copy ( const piojo_btree_t *  tree)

Copies tree and all its entries.

Parameters
[in]treeTree being copied.
Returns
New tree.
bool piojo_btree_delete ( const void *  key,
piojo_btree_t *  tree 
)

Deletes an entry by key.

Parameters
[in]keyEntry key.
[out]tree
Returns
TRUE if deleted, FALSE if key doesn't exist.
const void* piojo_btree_first ( const piojo_btree_t *  tree,
void **  data 
)

Reads the first key in tree (order given by keycmp function).

Parameters
[in]tree
[out]dataEntry value, can be NULL.
Returns
first key or NULL if tree is empty.
void piojo_btree_free ( const piojo_btree_t *  tree)

Frees tree and all its entries.

Parameters
[in]treeTree being freed.
bool piojo_btree_insert ( const void *  key,
const void *  data,
piojo_btree_t *  tree 
)

Inserts a new entry. If data is NULL, the value is replaced with TRUE (useful for sets).

Parameters
[in]keyEntry key.
[in]dataEntry value.
[out]treeTree being modified.
Returns
TRUE if inserted, FALSE if key is duplicate.
const void* piojo_btree_last ( const piojo_btree_t *  tree,
void **  data 
)

Reads the last key in tree (order given by keycmp function).

Parameters
[in]tree
[out]dataEntry value, can be NULL.
Returns
last key or NULL if tree is empty.
const void* piojo_btree_next ( const void *  key,
const piojo_btree_t *  tree,
void **  data 
)

Reads the next key (order given by keycmp function).

Parameters
[in]key
[in]tree
[out]dataEntry value, can be NULL.
Returns
next key or NULL if key is the last one.
const void* piojo_btree_prev ( const void *  key,
const piojo_btree_t *  tree,
void **  data 
)

Reads the previous key (order given by keycmp function).

Parameters
[in]key
[in]tree
[out]dataEntry value, can be NULL.
Returns
previous key or NULL if key is the first one.
void* piojo_btree_search ( const void *  key,
const piojo_btree_t *  tree 
)

Searches an entry by key.

Parameters
[in]keyEntry key.
[in]tree
Returns
Entry value or NULL if key doesn't exist.
bool piojo_btree_set ( const void *  key,
const void *  data,
piojo_btree_t *  tree 
)

Replaces or inserts an entry. If data is NULL, the value is replaced with TRUE (useful for sets).

Parameters
[in]keyEntry key.
[in]dataEntry value.
[out]treeTree being modified.
Returns
TRUE if key is new, FALSE otherwise.
size_t piojo_btree_size ( const piojo_btree_t *  tree)

Returns number of entries.

Parameters
[in]tree
Returns
Number of entries in tree.

Variable Documentation

const size_t piojo_btree_sizeof

Size of tree in bytes