gi-dazzle-1.0.2: libdazzle bindings
CopyrightWill Thompson and Iñaki García Etxebarria
LicenseLGPL-2.1
MaintainerIñaki García Etxebarria
Safe HaskellSafe-Inferred
LanguageHaskell2010

GI.Dazzle.Structs.Heap

Description

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 heapNew.

To add items to the heap, use dzl_heap_insert_val() or heapInsertVals to insert in bulk.

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

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

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

To free a heap, use heapUnref.

Here is an example that stores integers in a Heap:

C code

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);
}
Synopsis

Exported types

newtype Heap Source #

Memory-managed wrapper type.

Constructors

Heap (ManagedPtr Heap) 

Instances

Instances details
Eq Heap Source # 
Instance details

Defined in GI.Dazzle.Structs.Heap

Methods

(==) :: Heap -> Heap -> Bool #

(/=) :: Heap -> Heap -> Bool #

GBoxed Heap Source # 
Instance details

Defined in GI.Dazzle.Structs.Heap

ManagedPtrNewtype Heap Source # 
Instance details

Defined in GI.Dazzle.Structs.Heap

Methods

toManagedPtr :: Heap -> ManagedPtr Heap

TypedObject Heap Source # 
Instance details

Defined in GI.Dazzle.Structs.Heap

Methods

glibType :: IO GType

HasParentTypes Heap Source # 
Instance details

Defined in GI.Dazzle.Structs.Heap

tag ~ 'AttrSet => Constructible Heap tag Source # 
Instance details

Defined in GI.Dazzle.Structs.Heap

Methods

new :: MonadIO m => (ManagedPtr Heap -> Heap) -> [AttrOp Heap tag] -> m Heap

IsGValue (Maybe Heap) Source #

Convert Heap to and from GValue. See toGValue and fromGValue.

Instance details

Defined in GI.Dazzle.Structs.Heap

Methods

gvalueGType_ :: IO GType

gvalueSet_ :: Ptr GValue -> Maybe Heap -> IO ()

gvalueGet_ :: Ptr GValue -> IO (Maybe Heap)

type ParentTypes Heap Source # 
Instance details

Defined in GI.Dazzle.Structs.Heap

type ParentTypes Heap = '[] :: [Type]

newZeroHeap :: MonadIO m => m Heap Source #

Construct a Heap struct initialized to zero.

Methods

Click to display all available methods, including inherited ones

Expand

Methods

extract, extractIndex, insertVals, ref, unref.

Getters

None.

Setters

None.

extract

heapExtract :: (HasCallStack, MonadIO m) => Heap -> Ptr () -> m Bool Source #

No description available in the introspection data.

extractIndex

heapExtractIndex :: (HasCallStack, MonadIO m) => Heap -> CSize -> Ptr () -> m Bool Source #

No description available in the introspection data.

insertVals

heapInsertVals :: (HasCallStack, MonadIO m) => Heap -> Ptr () -> Word32 -> m () Source #

No description available in the introspection data.

new

heapNew Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Word32

elementSize: the size of each element in the heap

-> CompareFunc

compareFunc: a function to compare to elements

-> m Heap

Returns: A newly allocated Heap

Creates a new Heap. 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 compareFunc. This is also known as a priority queue.

ref

heapRef Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Heap

heap: An Heap

-> m Heap

Returns: heap

Increments the reference count of heap by one.

unref

heapUnref Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Heap

heap: An Heap

-> m () 

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

Properties

data

No description available in the introspection data.

clearHeapData :: MonadIO m => Heap -> m () Source #

Set the value of the “data” field to Nothing. When overloading is enabled, this is equivalent to

clear #data

getHeapData :: MonadIO m => Heap -> m (Maybe Text) Source #

Get the value of the “data” field. When overloading is enabled, this is equivalent to

get heap #data

setHeapData :: MonadIO m => Heap -> CString -> m () Source #

Set the value of the “data” field. When overloading is enabled, this is equivalent to

set heap [ #data := value ]

len

No description available in the introspection data.

getHeapLen :: MonadIO m => Heap -> m CSize Source #

Get the value of the “len” field. When overloading is enabled, this is equivalent to

get heap #len

setHeapLen :: MonadIO m => Heap -> CSize -> m () Source #

Set the value of the “len” field. When overloading is enabled, this is equivalent to

set heap [ #len := value ]