Gjsify LogoGjsify Logo

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

To add items to the heap, use egg_heap_insert_val() or egg_heap_insert_vals() to insert in bulk.

To access an item in the heap, use egg_heap_index().

To remove an arbitrary item from the heap, use egg_heap_extract_index().

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

To free a heap, use egg_heap_unref().

Here is an example that stores integers in a #EggHeap:

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

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

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

for (i = 0; i < 10000; i++)
egg_heap_insert_val (heap, i);
for (i = 0; i < 10000; i++)
egg_heap_extract (heap, &v);

egg_heap_unref (heap);
}
record

Hierarchy

  • Heap

Index

Constructors

  • Creates a new #EggHeap. 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.

    Parameters

    • elementSize: number

      the size of each element in the heap

    • compareFunc: CompareFunc

      a function to compare to elements

    Returns Egg.Heap

Properties

data: string
len: number
name: string

Methods

  • extract(result: object): boolean
  • extractIndex(index: number, result: object): boolean
  • insertVals(data: object, len: number): void
  • unref(): void
  • Decrements the reference count of heap by one, freeing the structure when the reference count reaches zero.

    Returns void

  • Creates a new #EggHeap. 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.

    Parameters

    • elementSize: number

      the size of each element in the heap

    • compareFunc: CompareFunc

      a function to compare to elements

    Returns Egg.Heap

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Type alias with type parameter
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method