Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2016-07-17 10:31:27 +0300
committerCampbell Barton <ideasman42@gmail.com>2016-07-17 12:29:30 +0300
commitc57d823683134d563e09e04b5079637885e89feb (patch)
tree3334ab38b079b0c422d5e6808f6eb14c9b565ba9 /source/blender/blenlib/intern/BLI_heap.c
parentd9281a6332d2273356e0d3d042d64157fb7d06c8 (diff)
Cleanup: minor edits to BLI_heap
Diffstat (limited to 'source/blender/blenlib/intern/BLI_heap.c')
-rw-r--r--source/blender/blenlib/intern/BLI_heap.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/source/blender/blenlib/intern/BLI_heap.c b/source/blender/blenlib/intern/BLI_heap.c
index 4bd404e5d73..8367d2419a4 100644
--- a/source/blender/blenlib/intern/BLI_heap.c
+++ b/source/blender/blenlib/intern/BLI_heap.c
@@ -52,7 +52,8 @@ struct Heap {
HeapNode **tree;
};
-/* internal functions */
+/** \name Internal Functions
+ * \{ */
#define HEAP_PARENT(i) (((i) - 1) >> 1)
#define HEAP_LEFT(i) (((i) << 1) + 1)
@@ -92,11 +93,13 @@ static void heap_down(Heap *heap, unsigned int i)
smallest = ((l < size) && HEAP_COMPARE(heap->tree[l], heap->tree[i])) ? l : i;
- if ((r < size) && HEAP_COMPARE(heap->tree[r], heap->tree[smallest]))
+ if ((r < size) && HEAP_COMPARE(heap->tree[r], heap->tree[smallest])) {
smallest = r;
+ }
- if (smallest == i)
+ if (smallest == i) {
break;
+ }
heap_swap(heap, i, smallest);
i = smallest;
@@ -108,25 +111,30 @@ static void heap_up(Heap *heap, unsigned int i)
while (i > 0) {
const unsigned int p = HEAP_PARENT(i);
- if (HEAP_COMPARE(heap->tree[p], heap->tree[i]))
+ if (HEAP_COMPARE(heap->tree[p], heap->tree[i])) {
break;
-
+ }
heap_swap(heap, p, i);
i = p;
}
}
+/** \} */
-/***/
+
+/** \name Public Heap API
+ * \{ */
/* use when the size of the heap is known in advance */
Heap *BLI_heap_new_ex(unsigned int tot_reserve)
{
- Heap *heap = (Heap *)MEM_callocN(sizeof(Heap), __func__);
+ Heap *heap = MEM_mallocN(sizeof(Heap), __func__);
/* ensure we have at least one so we can keep doubling it */
+ heap->size = 0;
heap->bufsize = MAX2(1u, tot_reserve);
- heap->tree = (HeapNode **)MEM_mallocN(heap->bufsize * sizeof(HeapNode *), "BLIHeapTree");
heap->arena = BLI_memarena_new(MEM_SIZE_OPTIMAL(1 << 16), "heap arena");
+ heap->freenodes = NULL;
+ heap->tree = MEM_mallocN(heap->bufsize * sizeof(HeapNode *), "BLIHeapTree");
return heap;
}
@@ -180,7 +188,7 @@ HeapNode *BLI_heap_insert(Heap *heap, float value, void *ptr)
heap->freenodes = heap->freenodes->ptr;
}
else {
- node = (HeapNode *)BLI_memarena_alloc(heap->arena, sizeof(*node));
+ node = BLI_memarena_alloc(heap->arena, sizeof(*node));
}
node->ptr = ptr;
@@ -254,3 +262,4 @@ void *BLI_heap_node_ptr(HeapNode *node)
return node->ptr;
}
+/** \} */