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>2012-03-12 03:47:41 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-03-12 03:47:41 +0400
commitcae11a98f98cf0fc299dbb641c6a748b83589054 (patch)
tree5700289684313664a07fd6480e9d9183f84cdf3a /source/blender/blenlib/intern/BLI_heap.c
parentac24d98e24c0d8d1dfd005d4f332e906f1b9664c (diff)
style cleanup
Diffstat (limited to 'source/blender/blenlib/intern/BLI_heap.c')
-rw-r--r--source/blender/blenlib/intern/BLI_heap.c35
1 files changed, 17 insertions, 18 deletions
diff --git a/source/blender/blenlib/intern/BLI_heap.c b/source/blender/blenlib/intern/BLI_heap.c
index 62a38e7933a..01a38cf123e 100644
--- a/source/blender/blenlib/intern/BLI_heap.c
+++ b/source/blender/blenlib/intern/BLI_heap.c
@@ -30,7 +30,6 @@
* \ingroup bli
*/
-
#include <string.h>
#include "MEM_guardedalloc.h"
@@ -55,26 +54,26 @@ struct Heap {
};
#define SWAP(type, a, b) \
- { type sw_ap; sw_ap=(a); (a)=(b); (b)=sw_ap; }
-#define HEAP_PARENT(i) ((i-1)>>1)
-#define HEAP_LEFT(i) ((i<<1)+1)
-#define HEAP_RIGHT(i) ((i<<1)+2)
+ { type sw_ap; sw_ap = (a); (a) = (b); (b) = sw_ap; }
+#define HEAP_PARENT(i) ((i - 1) >> 1)
+#define HEAP_LEFT(i) ((i << 1) + 1)
+#define HEAP_RIGHT(i) ((i << 1) + 2)
#define HEAP_COMPARE(a, b) (a->value < b->value)
#define HEAP_EQUALS(a, b) (a->value == b->value)
#define HEAP_SWAP(heap, i, j) \
{ \
SWAP(int, heap->tree[i]->index, heap->tree[j]->index); \
- SWAP(HeapNode*, heap->tree[i], heap->tree[j]); \
+ SWAP(HeapNode *, heap->tree[i], heap->tree[j]); \
}
/***/
Heap *BLI_heap_new(void)
{
- Heap *heap = (Heap*)MEM_callocN(sizeof(Heap), "BLIHeap");
+ Heap *heap = (Heap *)MEM_callocN(sizeof(Heap), __func__);
heap->bufsize = 1;
- heap->tree = (HeapNode**)MEM_mallocN(sizeof(HeapNode*), "BLIHeapTree");
- heap->arena = BLI_memarena_new(1<<16, "heap arena");
+ heap->tree = (HeapNode **)MEM_mallocN(sizeof(HeapNode *), "BLIHeapTree");
+ heap->arena = BLI_memarena_new(1 << 16, "heap arena");
return heap;
}
@@ -86,7 +85,7 @@ void BLI_heap_free(Heap *heap, HeapFreeFP ptrfreefp)
if (ptrfreefp)
for (i = 0; i < heap->size; i++)
ptrfreefp(heap->tree[i]->ptr);
-
+
MEM_freeN(heap->tree);
BLI_memarena_free(heap->arena);
MEM_freeN(heap);
@@ -99,11 +98,11 @@ static void BLI_heap_down(Heap *heap, int i)
int l = HEAP_LEFT(i);
int r = HEAP_RIGHT(i);
- smallest = ((l < size) && HEAP_COMPARE(heap->tree[l], heap->tree[i]))? l: 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]))
smallest = r;
-
+
if (smallest == i)
break;
@@ -130,11 +129,11 @@ HeapNode *BLI_heap_insert(Heap *heap, float value, void *ptr)
HeapNode *node;
if ((heap->size + 1) > heap->bufsize) {
- int newsize = heap->bufsize*2;
+ int newsize = heap->bufsize * 2;
HeapNode **newtree;
- newtree = (HeapNode**)MEM_mallocN(newsize*sizeof(*newtree), "BLIHeapTree");
- memcpy(newtree, heap->tree, sizeof(HeapNode*)*heap->size);
+ newtree = (HeapNode **)MEM_mallocN(newsize * sizeof(*newtree), __func__);
+ memcpy(newtree, heap->tree, sizeof(HeapNode *) * heap->size);
MEM_freeN(heap->tree);
heap->tree = newtree;
@@ -143,10 +142,10 @@ HeapNode *BLI_heap_insert(Heap *heap, float value, void *ptr)
if (heap->freenodes) {
node = heap->freenodes;
- heap->freenodes = (HeapNode*)(((HeapNode*)heap->freenodes)->ptr);
+ heap->freenodes = (HeapNode *)(((HeapNode *)heap->freenodes)->ptr);
}
else
- node = (HeapNode*)BLI_memarena_alloc(heap->arena, sizeof *node);
+ node = (HeapNode *)BLI_memarena_alloc(heap->arena, sizeof *node);
node->value = value;
node->ptr = ptr;
@@ -156,7 +155,7 @@ HeapNode *BLI_heap_insert(Heap *heap, float value, void *ptr)
heap->size++;
- BLI_heap_up(heap, heap->size-1);
+ BLI_heap_up(heap, heap->size - 1);
return node;
}