Lines Matching refs:heap
33 struct heap struct
43 struct heap *
46 struct heap *heap = xmalloc (sizeof *heap); in heap_alloc() local
51 heap->array = xnmalloc (n_reserve, sizeof *(heap->array)); in heap_alloc()
53 heap->array[0] = nullptr; in heap_alloc()
54 heap->capacity = n_reserve; in heap_alloc()
55 heap->count = 0; in heap_alloc()
56 heap->compare = compare ? compare : heap_default_compare; in heap_alloc()
58 return heap; in heap_alloc()
70 heap_free (struct heap *heap) in heap_free() argument
72 free (heap->array); in heap_free()
73 free (heap); in heap_free()
79 heap_insert (struct heap *heap, void *item) in heap_insert() argument
81 if (heap->capacity - 1 <= heap->count) in heap_insert()
82 heap->array = x2nrealloc (heap->array, &heap->capacity, in heap_insert()
83 sizeof *(heap->array)); in heap_insert()
85 heap->array[++heap->count] = item; in heap_insert()
86 heapify_up (heap->array, heap->count, heap->compare); in heap_insert()
94 heap_remove_top (struct heap *heap) in heap_remove_top() argument
98 if (heap->count == 0) in heap_remove_top()
101 top = heap->array[1]; in heap_remove_top()
102 heap->array[1] = heap->array[heap->count--]; in heap_remove_top()
103 heapify_down (heap->array, heap->count, 1, heap->compare); in heap_remove_top()