diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-12-09 02:32:20 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-12-09 02:32:20 +0300 |
commit | 83cbcefac8349d5ff46b721318ca180dd8817af5 (patch) | |
tree | 725a49c1fb21524efdbeb367432aeb6ab718d551 /source/blender/blenlib/intern/BLI_heap.c | |
parent | 55812e3acd625aa93162cd9e0894efd43a1dd615 (diff) |
Add edgehash remove, clear functions, Heap clear
Edgehash was missing removal functions (remove, popkey, clear),
since it wasn't needed so far, but is based on same code as ghash which has them.
also add heap clear() method so we can reuse heaps.
(needed for upcoming fix).
Diffstat (limited to 'source/blender/blenlib/intern/BLI_heap.c')
-rw-r--r-- | source/blender/blenlib/intern/BLI_heap.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/source/blender/blenlib/intern/BLI_heap.c b/source/blender/blenlib/intern/BLI_heap.c index 05bd1074bf0..66dfa87b7b9 100644 --- a/source/blender/blenlib/intern/BLI_heap.c +++ b/source/blender/blenlib/intern/BLI_heap.c @@ -138,9 +138,9 @@ Heap *BLI_heap_new(void) void BLI_heap_free(Heap *heap, HeapFreeFP ptrfreefp) { - unsigned int i; - if (ptrfreefp) { + unsigned int i; + for (i = 0; i < heap->size; i++) { ptrfreefp(heap->tree[i]->ptr); } @@ -151,6 +151,21 @@ void BLI_heap_free(Heap *heap, HeapFreeFP ptrfreefp) MEM_freeN(heap); } +void BLI_heap_clear(Heap *heap, HeapFreeFP ptrfreefp) +{ + if (ptrfreefp) { + unsigned int i; + + for (i = 0; i < heap->size; i++) { + ptrfreefp(heap->tree[i]->ptr); + } + } + + heap->size = 0; + BLI_memarena_clear(heap->arena); + heap->freenodes = NULL; +} + HeapNode *BLI_heap_insert(Heap *heap, float value, void *ptr) { HeapNode *node; |