diff options
author | Campbell Barton <ideasman42@gmail.com> | 2017-10-28 20:42:58 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2017-10-28 20:42:58 +0300 |
commit | 4af1af70ad41015d0126837e856d87b930f61655 (patch) | |
tree | ba792d315f1400f2042b2d1b529beee85e7388d8 /source | |
parent | b84e3dc7f390c7b8251fb4d8c10557693157cd31 (diff) |
BLI_hash: add BLI_heap_reinsert
Allows avoiding remove/insert calls.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenlib/BLI_heap.h | 3 | ||||
-rw-r--r-- | source/blender/blenlib/intern/BLI_heap.c | 10 |
2 files changed, 13 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_heap.h b/source/blender/blenlib/BLI_heap.h index ea361097b7b..cf18dfa5d2e 100644 --- a/source/blender/blenlib/BLI_heap.h +++ b/source/blender/blenlib/BLI_heap.h @@ -47,6 +47,9 @@ HeapNode *BLI_heap_insert(Heap *heap, float value, void *ptr) ATTR_NONNULL /* Remove a heap node. */ void BLI_heap_remove(Heap *heap, HeapNode *node) ATTR_NONNULL(1, 2); +/* Set new value for existing node. */ +void BLI_heap_reinsert(Heap *heap, HeapNode *node, float value); + /* Return 0 if the heap is empty, 1 otherwise. */ bool BLI_heap_is_empty(Heap *heap) ATTR_NONNULL(1); diff --git a/source/blender/blenlib/intern/BLI_heap.c b/source/blender/blenlib/intern/BLI_heap.c index 6b3d797a485..d794332b5df 100644 --- a/source/blender/blenlib/intern/BLI_heap.c +++ b/source/blender/blenlib/intern/BLI_heap.c @@ -306,6 +306,16 @@ void *BLI_heap_popmin(Heap *heap) return ptr; } +void BLI_heap_reinsert(Heap *heap, HeapNode *node, float value) +{ + if (value == node->value) { + return; + } + node->value = value; + heap_up(heap, node->index); + heap_down(heap, node->index); +} + void BLI_heap_remove(Heap *heap, HeapNode *node) { uint i = node->index; |