Lines Matching refs:ctx

51 	heap_context ctx;  in heap_new()  local
56 ctx = (heap_context)malloc(sizeof (struct heap_context)); in heap_new()
57 if (ctx == NULL) in heap_new()
60 ctx->array_size = 0; in heap_new()
62 ctx->array_size_increment = ARRAY_SIZE_INCREMENT; in heap_new()
64 ctx->array_size_increment = array_size_increment; in heap_new()
65 ctx->heap_size = 0; in heap_new()
66 ctx->heap = NULL; in heap_new()
67 ctx->higher_priority = higher_priority; in heap_new()
68 ctx->index = index; in heap_new()
69 return (ctx); in heap_new()
73 heap_free(heap_context ctx) { in heap_free() argument
74 if (ctx == NULL) { in heap_free()
79 if (ctx->heap != NULL) in heap_free()
80 free(ctx->heap); in heap_free()
81 free(ctx); in heap_free()
87 heap_resize(heap_context ctx) { in heap_resize() argument
90 ctx->array_size += ctx->array_size_increment; in heap_resize()
91 new_heap = (void **)realloc(ctx->heap, in heap_resize()
92 (ctx->array_size) * (sizeof (void *))); in heap_resize()
97 ctx->heap = new_heap; in heap_resize()
102 float_up(heap_context ctx, int i, void *elt) { in float_up() argument
106 i > 1 && ctx->higher_priority(elt, ctx->heap[p]); in float_up()
108 ctx->heap[i] = ctx->heap[p]; in float_up()
109 if (ctx->index != NULL) in float_up()
110 (ctx->index)(ctx->heap[i], i); in float_up()
112 ctx->heap[i] = elt; in float_up()
113 if (ctx->index != NULL) in float_up()
114 (ctx->index)(ctx->heap[i], i); in float_up()
118 sink_down(heap_context ctx, int i, void *elt) { in sink_down() argument
121 size = ctx->heap_size; in sink_down()
126 if (j < size && ctx->higher_priority(ctx->heap[j+1], in sink_down()
127 ctx->heap[j])) in sink_down()
129 if (ctx->higher_priority(elt, ctx->heap[j])) in sink_down()
131 ctx->heap[i] = ctx->heap[j]; in sink_down()
132 if (ctx->index != NULL) in sink_down()
133 (ctx->index)(ctx->heap[i], i); in sink_down()
136 ctx->heap[i] = elt; in sink_down()
137 if (ctx->index != NULL) in sink_down()
138 (ctx->index)(ctx->heap[i], i); in sink_down()
142 heap_insert(heap_context ctx, void *elt) { in heap_insert() argument
145 if (ctx == NULL || elt == NULL) { in heap_insert()
150 i = ++ctx->heap_size; in heap_insert()
151 if (ctx->heap_size >= ctx->array_size && heap_resize(ctx) < 0) in heap_insert()
154 float_up(ctx, i, elt); in heap_insert()
160 heap_delete(heap_context ctx, int i) { in heap_delete() argument
164 if (ctx == NULL || i < 1 || i > ctx->heap_size) { in heap_delete()
169 if (i == ctx->heap_size) { in heap_delete()
170 ctx->heap_size--; in heap_delete()
172 elt = ctx->heap[ctx->heap_size--]; in heap_delete()
173 less = ctx->higher_priority(elt, ctx->heap[i]); in heap_delete()
174 ctx->heap[i] = elt; in heap_delete()
176 float_up(ctx, i, ctx->heap[i]); in heap_delete()
178 sink_down(ctx, i, ctx->heap[i]); in heap_delete()
185 heap_increased(heap_context ctx, int i) { in heap_increased() argument
186 if (ctx == NULL || i < 1 || i > ctx->heap_size) { in heap_increased()
191 float_up(ctx, i, ctx->heap[i]); in heap_increased()
197 heap_decreased(heap_context ctx, int i) { in heap_decreased() argument
198 if (ctx == NULL || i < 1 || i > ctx->heap_size) { in heap_decreased()
203 sink_down(ctx, i, ctx->heap[i]); in heap_decreased()
209 heap_element(heap_context ctx, int i) { in heap_element() argument
210 if (ctx == NULL || i < 1 || i > ctx->heap_size) { in heap_element()
215 return (ctx->heap[i]); in heap_element()
219 heap_for_each(heap_context ctx, heap_for_each_func action, void *uap) { in heap_for_each() argument
222 if (ctx == NULL || action == NULL) { in heap_for_each()
227 for (i = 1; i <= ctx->heap_size; i++) in heap_for_each()
228 (action)(ctx->heap[i], uap); in heap_for_each()