[Bf-blender-cvs] [c57d823] master: Cleanup: minor edits to BLI_heap

Campbell Barton noreply at git.blender.org
Sun Jul 17 11:24:54 CEST 2016


Commit: c57d823683134d563e09e04b5079637885e89feb
Author: Campbell Barton
Date:   Sun Jul 17 17:31:27 2016 +1000
Branches: master
https://developer.blender.org/rBc57d823683134d563e09e04b5079637885e89feb

Cleanup: minor edits to BLI_heap

===================================================================

M	source/blender/blenlib/intern/BLI_heap.c

===================================================================

diff --git a/source/blender/blenlib/intern/BLI_heap.c b/source/blender/blenlib/intern/BLI_heap.c
index 4bd404e..8367d24 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;
 }
 
+/** \} */




More information about the Bf-blender-cvs mailing list