Lines Matching refs:ctx

55 	heap_context ctx;  in heap_new()  local
60 ctx = (heap_context)malloc(sizeof (struct heap_context)); in heap_new()
61 if (ctx == NULL) in heap_new()
64 ctx->array_size = 0; in heap_new()
66 ctx->array_size_increment = ARRAY_SIZE_INCREMENT; in heap_new()
68 ctx->array_size_increment = array_size_increment; in heap_new()
69 ctx->heap_size = 0; in heap_new()
70 ctx->heap = NULL; in heap_new()
71 ctx->higher_priority = higher_priority; in heap_new()
72 ctx->index = index; in heap_new()
73 return (ctx); in heap_new()
77 heap_free(heap_context ctx) { in heap_free() argument
78 if (ctx == NULL) { in heap_free()
83 if (ctx->heap != NULL) in heap_free()
84 free(ctx->heap); in heap_free()
85 free(ctx); in heap_free()
91 heap_resize(heap_context ctx) { in heap_resize() argument
94 ctx->array_size += ctx->array_size_increment; in heap_resize()
95 new_heap = (void **)realloc(ctx->heap, in heap_resize()
96 (ctx->array_size) * (sizeof (void *))); in heap_resize()
101 ctx->heap = new_heap; in heap_resize()
106 float_up(heap_context ctx, int i, void *elt) { in float_up() argument
110 i > 1 && ctx->higher_priority(elt, ctx->heap[p]); in float_up()
112 ctx->heap[i] = ctx->heap[p]; in float_up()
113 if (ctx->index != NULL) in float_up()
114 (ctx->index)(ctx->heap[i], i); in float_up()
116 ctx->heap[i] = elt; in float_up()
117 if (ctx->index != NULL) in float_up()
118 (ctx->index)(ctx->heap[i], i); in float_up()
122 sink_down(heap_context ctx, int i, void *elt) { in sink_down() argument
125 size = ctx->heap_size; in sink_down()
130 if (j < size && ctx->higher_priority(ctx->heap[j+1], in sink_down()
131 ctx->heap[j])) in sink_down()
133 if (ctx->higher_priority(elt, ctx->heap[j])) in sink_down()
135 ctx->heap[i] = ctx->heap[j]; in sink_down()
136 if (ctx->index != NULL) in sink_down()
137 (ctx->index)(ctx->heap[i], i); in sink_down()
140 ctx->heap[i] = elt; in sink_down()
141 if (ctx->index != NULL) in sink_down()
142 (ctx->index)(ctx->heap[i], i); in sink_down()
146 heap_insert(heap_context ctx, void *elt) { in heap_insert() argument
149 if (ctx == NULL || elt == NULL) { in heap_insert()
154 i = ++ctx->heap_size; in heap_insert()
155 if (ctx->heap_size >= ctx->array_size && heap_resize(ctx) < 0) in heap_insert()
158 float_up(ctx, i, elt); in heap_insert()
164 heap_delete(heap_context ctx, int i) { in heap_delete() argument
168 if (ctx == NULL || i < 1 || i > ctx->heap_size) { in heap_delete()
173 if (i == ctx->heap_size) { in heap_delete()
174 ctx->heap_size--; in heap_delete()
176 elt = ctx->heap[ctx->heap_size--]; in heap_delete()
177 less = ctx->higher_priority(elt, ctx->heap[i]); in heap_delete()
178 ctx->heap[i] = elt; in heap_delete()
180 float_up(ctx, i, ctx->heap[i]); in heap_delete()
182 sink_down(ctx, i, ctx->heap[i]); in heap_delete()
189 heap_increased(heap_context ctx, int i) { in heap_increased() argument
190 if (ctx == NULL || i < 1 || i > ctx->heap_size) { in heap_increased()
195 float_up(ctx, i, ctx->heap[i]); in heap_increased()
201 heap_decreased(heap_context ctx, int i) { in heap_decreased() argument
202 if (ctx == NULL || i < 1 || i > ctx->heap_size) { in heap_decreased()
207 sink_down(ctx, i, ctx->heap[i]); in heap_decreased()
213 heap_element(heap_context ctx, int i) { in heap_element() argument
214 if (ctx == NULL || i < 1 || i > ctx->heap_size) { in heap_element()
219 return (ctx->heap[i]); in heap_element()
223 heap_for_each(heap_context ctx, heap_for_each_func action, void *uap) { in heap_for_each() argument
226 if (ctx == NULL || action == NULL) { in heap_for_each()
231 for (i = 1; i <= ctx->heap_size; i++) in heap_for_each()
232 (action)(ctx->heap[i], uap); in heap_for_each()