Add heap data structure
This commit is contained in:
28
engine/breeze/utils/heap.h
Normal file
28
engine/breeze/utils/heap.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef BREEZE_HEAP_H
|
||||
#define BREEZE_HEAP_H
|
||||
|
||||
#include "../defines.h"
|
||||
|
||||
void *_bzHeapNew(i32 startCapacity, i32 stride, i32 weightOffset);
|
||||
void _bzHeapFree(void *heap);
|
||||
|
||||
i32 _bzHeapSize(void *heap);
|
||||
bool _bzHeapIsEmpty(void *heap);
|
||||
i32 _bzHeapPop(void *heap);
|
||||
void _bzHeapPush(void *heap);
|
||||
i32 _bzHeapPushTmpIdx(void *heap);
|
||||
|
||||
#define bzHeapNew(T, n) (T *) ((T *)_bzHeapNew((n), sizeof(T), offsetof(T, weight)))
|
||||
#define bzHeapFree(heap) _bzHeapFree((void *) (heap))
|
||||
|
||||
#define bzHeapSize(heap) _bzHeapSize((void *) (heap))
|
||||
#define bzHeapIsEmpty(heap) _bzHeapIsEmpty((void *) (heap))
|
||||
#define bzHeapPop(heap) ((heap)[_bzHeapPop((void *) (heap))])
|
||||
#define bzHeapPush(heap, item) do { \
|
||||
void *h = (void *) (heap); \
|
||||
(heap)[_bzHeapPushTmpIdx(h)] = (item); \
|
||||
_bzHeapPush(h); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#endif //BREEZE_HEAP_H
|
||||
Reference in New Issue
Block a user