libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_array_heap.h
Go to the documentation of this file.
1/*! \file
2 * \brief GblArrayHeap container and related functions
3 * \ingroup containers
4 * \copydoc GblArrayHeap
5 *
6 * \author Falco Girgis
7 */
8#ifndef GIMBAL_ARRAY_HEAP_H
9#define GIMBAL_ARRAY_HEAP_H
10
12
13#define GBL_SELF_TYPE GblArrayHeap
14
16
17typedef int (*GblArrayHeapCmpFn)(const void* pEntry1, const void* pEntry2);
18
19
20/*! \brief Array-based binary heap implementing priority queue
21 *
22 * GblArrayHeap is a dynamic array-backed (GblArrayList)
23 * binary heap, providing a priority queue implementation.
24 *
25 * \note
26 * As GblArrayMap is backed by GblArrayList, it also can be
27 * over-allocated to provide additional storage for the
28 * underlying data before bleeding over an allocating
29 * storage from the heap.
30 * \sa GblArrayList
31 * \ingroup containers
32 */
33typedef struct GblArrayHeap { // Size (32-bit / 64-bit)
35 GblArrayHeapCmpFn pFnCmp; // 4/8 bytes
36 GblArrayList list; // 20/36 bytes
38} GblArrayHeap; // 24/42 total
39
40// ===== Public Methods ======
41GBL_EXPORT GBL_RESULT GblArrayHeap_construct (GBL_SELF,
42 size_t elemSize,
43 GblArrayHeapCmpFn pFnCmp,
44 size_t structSize,
45 GblContext* pCtx) GBL_NOEXCEPT;
46
47GBL_EXPORT GBL_RESULT GblArrayHeap_acquire (GBL_SELF,
48 void* pData,
49 size_t size,
50 size_t capacity) GBL_NOEXCEPT;
51
52GBL_EXPORT GBL_RESULT GblArrayHeap_release (GBL_SELF,
53 void** ppData,
54 size_t * pSize,
55 size_t * pCapacity) GBL_NOEXCEPT;
56
57GBL_EXPORT GBL_RESULT GblArrayHeap_destruct (GBL_SELF) GBL_NOEXCEPT;
58GBL_EXPORT GBL_RESULT GblArrayHeap_copy (GBL_SELF, const GBL_SELF_TYPE* pRhs) GBL_NOEXCEPT;
59GBL_EXPORT GBL_RESULT GblArrayHeap_move (GBL_SELF, GBL_SELF_TYPE* pRhs) GBL_NOEXCEPT;
60
61GBL_EXPORT GblContext* GblArrayHeap_context (GBL_CSELF) GBL_NOEXCEPT;
62GBL_EXPORT size_t GblArrayHeap_elementSize (GBL_CSELF) GBL_NOEXCEPT;
63GBL_EXPORT size_t GblArrayHeap_size (GBL_CSELF) GBL_NOEXCEPT;
64GBL_EXPORT size_t GblArrayHeap_capacity (GBL_CSELF) GBL_NOEXCEPT;
65GBL_EXPORT GblBool GblArrayHeap_empty (GBL_CSELF) GBL_NOEXCEPT;
66GBL_EXPORT GblBool GblArrayHeap_stack (GBL_CSELF) GBL_NOEXCEPT;
67GBL_EXPORT void* GblArrayHeap_data (GBL_CSELF) GBL_NOEXCEPT;
68
69GBL_EXPORT void* GblArrayHeap_peek (GBL_CSELF) GBL_NOEXCEPT;
70GBL_EXPORT GBL_RESULT GblArrayHeap_pop (GBL_SELF, void* pEntryOut) GBL_NOEXCEPT;
71GBL_EXPORT GBL_RESULT GblArrayHeap_push (GBL_SELF, const void* pEntry) GBL_NOEXCEPT;
72
73GBL_EXPORT GBL_RESULT GblArrayHeap_clear (GBL_SELF) GBL_NOEXCEPT;
74GBL_EXPORT GBL_RESULT GblArrayHeap_reserve (GBL_SELF, size_t capacity) GBL_NOEXCEPT;
75GBL_EXPORT GBL_RESULT GblArrayHeap_shrinkToFit (GBL_SELF) GBL_NOEXCEPT;
76
78
79//! \cond
80#define GblArrayHeap_construct(...)
81 GblArrayHeap_constructDefault_(__VA_ARGS__)
82#define GblArrayHeap_constructDefault_(...)
83 GblArrayHeap_constructDefault__(__VA_ARGS__, sizeof(GblArrayHeap), GBL_NULL)
84#define GblArrayHeap_constructDefault__(self, elemSize, cmp, structSize, ctx, ...)
85 (GblArrayHeap_construct)(self, elemSize, cmp, structSize, ctx)
86//! \endcond
87
88#undef GBL_SELF_TYPE
89
90#endif // GIMBAL_ARRAY_HEAP_H
#define GBL_NULL
#define GBL_NOEXCEPT
#define GBL_DECLS_BEGIN
#define GBL_PRIVATE_BEGIN
#define GBL_EXPORT
#define GBL_PRIVATE_END
Private data structure.
#define GBL_SELF_TYPE
Definition gimbal_md5.h:22
uint8_t GblBool
Basic boolean type, standardized to sizeof(char)
Array-based binary heap implementing priority queue.