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

Typedefs

typedef int piojo_heap_key_t
 
typedef bool(* piojo_heap_leq_cb )(piojo_opaque_t e1, piojo_opaque_t e2)
 

Functions

piojo_heap_t * piojo_heap_alloc (piojo_heap_leq_cb leq)
 
piojo_heap_t * piojo_heap_alloc_cb (piojo_heap_leq_cb leq, piojo_alloc_if allocator)
 
piojo_heap_t * piojo_heap_copy (const piojo_heap_t *heap)
 
void piojo_heap_free (const piojo_heap_t *heap)
 
void piojo_heap_clear (piojo_heap_t *heap)
 
void piojo_heap_resize (size_t ecount, piojo_heap_t *heap)
 
size_t piojo_heap_size (const piojo_heap_t *heap)
 
void piojo_heap_push (piojo_opaque_t data, piojo_heap_t *heap)
 
void piojo_heap_decrease (piojo_opaque_t data, piojo_heap_t *heap)
 
void piojo_heap_pop (piojo_heap_t *heap)
 
piojo_opaque_t piojo_heap_peek (const piojo_heap_t *heap)
 
bool piojo_heap_contain_p (piojo_opaque_t data, const piojo_heap_t *heap)
 

Variables

const size_t piojo_heap_sizeof
 

Detailed Description

Piojo Heap (min-heap) implementation.

Typedef Documentation

typedef int piojo_heap_key_t

Priority key.

typedef bool(* piojo_heap_leq_cb)(piojo_opaque_t e1, piojo_opaque_t e2)

Returns TRUE if e1 is less or equal to e2, FALSE otherwise.

Function Documentation

piojo_heap_t* piojo_heap_alloc ( piojo_heap_leq_cb  leq)

Allocates a new heap. Uses default allocator.

Parameters
[in]leqEntry comparison function.
Returns
New heap.
piojo_heap_t* piojo_heap_alloc_cb ( piojo_heap_leq_cb  leq,
piojo_alloc_if  allocator 
)

Allocates a new heap.

Parameters
[in]leqEntry comparison function.
[in]allocatorAllocator to be used.
Returns
New heap.
void piojo_heap_clear ( piojo_heap_t *  heap)

Deletes all entries in heap.

Parameters
[out]heapHeap being cleared.
bool piojo_heap_contain_p ( piojo_opaque_t  data,
const piojo_heap_t *  heap 
)

Searches entry in heap.

Parameters
[in]dataEntry value.
[in]heap
Returns
TRUE if entry is in heap, FALSE otherwise.
piojo_heap_t* piojo_heap_copy ( const piojo_heap_t *  heap)

Copies heap and all its entries.

Parameters
[in]heapHeap being copied.
Returns
New heap.
void piojo_heap_decrease ( piojo_opaque_t  data,
piojo_heap_t *  heap 
)

Decreases existing entry key.

Parameters
[in]dataEntry value.
[out]heapHeap being modified.
void piojo_heap_free ( const piojo_heap_t *  heap)

Frees heap and all its entries.

Parameters
[in]heapHeap being freed.
piojo_opaque_t piojo_heap_peek ( const piojo_heap_t *  heap)

Reads the minimum entry according to key.

Parameters
[in]heapNon-empty heap.
Returns
Entry value.
void piojo_heap_pop ( piojo_heap_t *  heap)

Deletes the minimum entry according to key.

Parameters
[out]heapNon-empty heap.
void piojo_heap_push ( piojo_opaque_t  data,
piojo_heap_t *  heap 
)

Inserts a new entry.

Warning
data can't be inserted more than once.
Parameters
[in]dataEntry value.
[out]heapHeap being modified.
void piojo_heap_resize ( size_t  ecount,
piojo_heap_t *  heap 
)

Expands or shrinks allocated memory for ecount entries.

Parameters
[in]ecountMust be equal or greater than the current size.
[out]heapHeap being modified.
size_t piojo_heap_size ( const piojo_heap_t *  heap)

Returns number of entries.

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

Variable Documentation

const size_t piojo_heap_sizeof

Size of heap in bytes