Lines Matching defs:ctx

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