Heap


Object Hierarchy:

Dazzle.Heap Dazzle.Heap Dazzle.Heap

Description:

[ CCode ( ref_function = "dzl_heap_ref" , type_id = "dzl_heap_get_type ()" , unref_function = "dzl_heap_unref" ) ]
[ Compact ]
public class Heap

Heaps are similar to a partially sorted tree but implemented as an array.

They allow for efficient O(1) lookup of the highest priority item as it will always be the first item of the array.

To create a new heap use Heap.

To add items to the heap, use dzl_heap_insert_val or insert_vals to insert in bulk.

To access an item in the heap, use dzl_heap_index.

To remove an arbitrary item from the heap, use extract_index.

To remove the highest priority item in the heap, use extract.

To free a heap, use unref.

Here is an example that stores integers in a Heap:

static int
cmpint (gconstpointer a,
gconstpointer b)
{
return *(const gint *)a - *(const gint *)b;
}

int
main (gint argc,
gchar *argv[])
{
DzlHeap *heap;
gint i;
gint v;

heap = dzl_heap_new (sizeof (gint), cmpint);

for (i = 0; i < 10000; i++)
dzl_heap_insert_val (heap, i);
for (i = 0; i < 10000; i++)
dzl_heap_extract (heap, &v);

dzl_heap_unref (heap);
}

Namespace: Dazzle
Package: libdazzle-1.0

Content:

Creation methods:

Methods:

Fields:




2022 vala-language.org