X-Git-Url: https://git.auder.net/?p=cgds.git;a=blobdiff_plain;f=src%2FHeap.c;h=6bdbc0ee8818125b30ff2cdf898666f260ffe942;hp=e1cb8cea4694f421325808543525d18fe62125e3;hb=eed1b5d2fca21abae2540b500f4a4ed94a809403;hpb=e45132acdb58c076d5e06849fa51c26de9a7486d diff --git a/src/Heap.c b/src/Heap.c index e1cb8ce..6bdbc0e 100644 --- a/src/Heap.c +++ b/src/Heap.c @@ -4,7 +4,7 @@ #include "cgds/Heap.h" -// NOTE: no _init() method here, since Heap has no specific initialization +// NOTE: no init() method here, since Heap has no specific initialization Heap* _heap_new(size_t dataSize, OrderType hType, UInt arity) { @@ -25,7 +25,7 @@ Heap* heap_copy(Heap* heap) heapCopy->array->capacity = heap->array->capacity; heapCopy->array->datas = (void**)safe_malloc(heap->array->capacity*sizeof(void*)); - for (UInt i=0; iarray->size; i++) + for (UInt i = 0; i < heap->array->size; i++) { heapCopy->array->datas[i] = safe_malloc(sizeof(ItemValue)); ItemValue itemValueCopy = (ItemValue){ @@ -94,7 +94,7 @@ void _heap_bubble_down(Heap* heap, UInt startIndex) // find top child (min or max) UInt topChildIndex; Real topChildValue = (heap->hType == MIN_T ? INFINITY : -INFINITY); - for (Int i=0; iarity; i++) + for (UInt i = 0; i < heap->arity; i++) { UInt childIndex = i + currentIndex * heap->arity; if (childIndex >= heap->array->size) @@ -170,11 +170,8 @@ void heap_pop(Heap* heap) void heap_clear(Heap* heap) { for (UInt i = 0; i < heap->array->size; i++) - { // Extra memory releases which wouldn't be done in vector_clear() safe_free(((ItemValue*)(heap->array->datas[i]))->item); - //safe_free((ItemValue*)heap->array->datas[i]); - } vector_clear(heap->array); }