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 dzl_heap_new().

To add items to the heap, use dzl_heap_insert_val() or dzl_heap_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 dzl_heap_extract_index().

To remove the highest priority item in the heap, use dzl_heap_extract().

To free a heap, use dzl_heap_unref().

Here is an example that stores integers in a #DzlHeap: |[<!-- language="C" --> 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); } ]|

Constructors

this
this(DzlHeap* dzlHeap, bool ownedRef = false)

Sets our main struct and passes it to the parent class.

this
this(uint elementSize, GCompareFunc compareFunc)

Creates a new #DzlHeap. A heap is a tree-like structure stored in an array that is not fully sorted, but head is guaranteed to be either the max, or min value based on @compare_func. This is also known as a priority queue.

Destructor

A destructor is present on this object, but not explicitly documented in the source.

Members

Functions

data
string data()
void data(string value)
extract
bool extract(void* result)
extractIndex
bool extractIndex(size_t index, void* result)
getHeapStruct
DzlHeap* getHeapStruct(bool transferOwnership = false)

Get the main Gtk struct

getStruct
void* getStruct()

the main Gtk struct as a void*

insertVals
void insertVals(void* data, uint len)
len
size_t len()
void len(size_t value)
ref_
Heap ref_()

Increments the reference count of @heap by one.

unref
void unref()

Decrements the reference count of @heap by one, freeing the structure when the reference count reaches zero.

Static functions

getType
GType getType()

Variables

dzlHeap
DzlHeap* dzlHeap;

the main Gtk struct

Meta