Copyright | Will Thompson and Iñaki García Etxebarria |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
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
- newtype Heap = Heap (ManagedPtr Heap)
- newZeroHeap :: MonadIO m => m Heap
- heapExtract :: (HasCallStack, MonadIO m) => Heap -> Ptr () -> m Bool
- heapExtractIndex :: (HasCallStack, MonadIO m) => Heap -> CSize -> Ptr () -> m Bool
- heapInsertVals :: (HasCallStack, MonadIO m) => Heap -> Ptr () -> Word32 -> m ()
- heapNew :: (HasCallStack, MonadIO m) => Word32 -> CompareFunc -> m Heap
- heapRef :: (HasCallStack, MonadIO m) => Heap -> m Heap
- heapUnref :: (HasCallStack, MonadIO m) => Heap -> m ()
- clearHeapData :: MonadIO m => Heap -> m ()
- getHeapData :: MonadIO m => Heap -> m (Maybe Text)
- setHeapData :: MonadIO m => Heap -> CString -> m ()
- getHeapLen :: MonadIO m => Heap -> m CSize
- setHeapLen :: MonadIO m => Heap -> CSize -> m ()
Exported types
Memory-managed wrapper type.
Instances
Eq Heap Source # | |
GBoxed Heap Source # | |
Defined in GI.Dazzle.Structs.Heap | |
ManagedPtrNewtype Heap Source # | |
Defined in GI.Dazzle.Structs.Heap Methods toManagedPtr :: Heap -> ManagedPtr Heap | |
TypedObject Heap Source # | |
Defined in GI.Dazzle.Structs.Heap | |
HasParentTypes Heap Source # | |
Defined in GI.Dazzle.Structs.Heap | |
tag ~ 'AttrSet => Constructible Heap tag Source # | |
IsGValue (Maybe Heap) Source # | Convert |
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 # | |
Defined in GI.Dazzle.Structs.Heap |
Methods
Click to display all available methods, including inherited ones
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
Arguments
:: (HasCallStack, MonadIO m) | |
=> Word32 |
|
-> CompareFunc |
|
-> m Heap | Returns: A newly allocated |
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
Arguments
:: (HasCallStack, MonadIO m) | |
=> Heap |
|
-> m Heap | Returns: |
Increments the reference count of heap
by one.
unref
Arguments
:: (HasCallStack, MonadIO m) | |
=> 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 ]