piojo-0.9
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

◆ piojo_heap_key_t

typedef int piojo_heap_key_t

Priority key.

◆ piojo_heap_leq_cb

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_alloc()

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_alloc_cb()

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.

◆ piojo_heap_clear()

void piojo_heap_clear ( piojo_heap_t *  heap)

Deletes all entries in heap.

Parameters
[out]heapHeap being cleared.

◆ piojo_heap_contain_p()

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_copy()

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.

◆ piojo_heap_decrease()

void piojo_heap_decrease ( piojo_opaque_t  data,
piojo_heap_t *  heap 
)

Decreases existing entry key.

Parameters
[in]dataEntry value.
[out]heapHeap being modified.

◆ piojo_heap_free()

void piojo_heap_free ( const piojo_heap_t *  heap)

Frees heap and all its entries.

Parameters
[in]heapHeap being freed.

◆ piojo_heap_peek()

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.

◆ piojo_heap_pop()

void piojo_heap_pop ( piojo_heap_t *  heap)

Deletes the minimum entry according to key.

Parameters
[out]heapNon-empty heap.

◆ piojo_heap_push()

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.

◆ piojo_heap_resize()

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.

◆ piojo_heap_size()

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

◆ piojo_heap_sizeof

const size_t piojo_heap_sizeof

Size of heap in bytes