43#define HEAP_CHUNK_DEFAULT_NUM \
44 (uint)(MEM_SIZE_OPTIMAL((1 << 16) - sizeof(struct HeapNode_Chunk)) / sizeof(HeapNode))
63#define HEAP_PARENT(i) (((i)-1) >> 1)
64#define HEAP_LEFT(i) (((i) << 1) + 1)
65#define HEAP_RIGHT(i) (((i) << 1) + 2)
66#define HEAP_COMPARE(a, b) ((a)->value < (b)->value)
69# define HEAP_EQUALS(a, b) ((a)->value == (b)->value)
135 chunk->
prev = chunk_prev;
154 node = &chunk->
buf[chunk->
size++];
197 for (i = 0; i < heap->
size; i++) {
205 chunk_prev = chunk->
prev;
219 for (i = 0; i < heap->
size; i++) {
248 node->index = heap->
size;
261 if (*node_p ==
NULL) {
271 return (heap->
size == 0);
281 return heap->
tree[0];
311 uint i = node->index;
324 if (value < node->value) {
328 else if (value > node->value) {
337 if (value < node->value) {
341 else if (value > node->value) {
359 if (root < heap->size) {
370 if (r < heap->size) {
void * BLI_heap_node_ptr(const HeapNode *heap)
bool BLI_heap_is_valid(const Heap *heap)
void BLI_heap_insert_or_update(Heap *heap, HeapNode **node_p, float value, void *ptr)
void BLI_heap_node_value_update_ptr(Heap *heap, HeapNode *node, float value, void *ptr)
BLI_INLINE void heap_swap(Heap *heap, const uint i, const uint j)
void * BLI_heap_pop_min(Heap *heap)
void BLI_heap_free(Heap *heap, HeapFreeFP ptrfreefp)
static void heap_down(Heap *heap, uint i)
void BLI_heap_clear(Heap *heap, HeapFreeFP ptrfreefp)
bool BLI_heap_is_empty(const Heap *heap)
void BLI_heap_remove(Heap *heap, HeapNode *node)
static struct HeapNode_Chunk * heap_node_alloc_chunk(uint nodes_num, struct HeapNode_Chunk *chunk_prev)
static void heap_up(Heap *heap, uint i)
uint BLI_heap_len(const Heap *heap)
HeapNode * BLI_heap_top(const Heap *heap)
static void heap_node_free(Heap *heap, HeapNode *node)
HeapNode * BLI_heap_insert(Heap *heap, float value, void *ptr)
static bool heap_is_minheap(const Heap *heap, uint root)
Heap * BLI_heap_new_ex(uint reserve_num)
float BLI_heap_node_value(const HeapNode *heap)
static HeapNode * heap_node_alloc(Heap *heap)
#define HEAP_CHUNK_DEFAULT_NUM
Heap * BLI_heap_new(void)
#define HEAP_COMPARE(a, b)
void BLI_heap_node_value_update(Heap *heap, HeapNode *node, float value)
float BLI_heap_top_value(const Heap *heap)
A min-heap / priority queue ADT.
void(* HeapFreeFP)(void *ptr)
Read Guarded memory(de)allocation.
#define MEM_reallocN(vmemh, len)
ATTR_WARN_UNUSED_RESULT const BMLoop * l
void *(* MEM_mallocN)(size_t len, const char *str)
void MEM_freeN(void *vmemh)
struct HeapNode_Chunk * prev
struct HeapNode_Chunk * chunk