Esempio n. 1
0
static inline void max_heapify(struct ast_heap *h, int i)
{
	for (;;) {
		int l = left_node(i);
		int r = right_node(i);
		int max;

		if (l <= h->cur_len && h->cmp_fn(heap_get(h, l), heap_get(h, i)) > 0) {
			max = l;
		} else {
			max = i;
		}

		if (r <= h->cur_len && h->cmp_fn(heap_get(h, r), heap_get(h, max)) > 0) {
			max = r;
		}

		if (max == i) {
			break;
		}

		heap_swap(h, i, max);

		i = max;
	}
}
Esempio n. 2
0
File: heap.c Progetto: kcyeu/xcb
static void max_heapify(heap_t heap, unsigned long i) {
	for (;;) {
		unsigned long l = left_node(i), r = right_node(i), max;

		max = l <= heap->curr && heap->cmp(heap_get(heap, l), heap_get(heap, i)) > 0
			? l : i;
		if (r <= heap->curr && heap->cmp(heap_get(heap, r), heap_get(heap, max)) > 0)
			max = r;
		if (max == i)
			break;
		heap_swap(heap, i, max);
		i = max;
	}
}
Esempio n. 3
0
File: heap.c Progetto: ai-ku/dist
void max_heapify(Heap h, unsigned int idx){
     unsigned int l = 0 ,r = 0, sz = 0, largest = 0;
     l = left_node(idx);
     r = right_node(idx);
     sz = heap_size(h);
     largest = idx;
     if (l <= sz  && h[l].val > h[idx].val){
          largest = l;
     }
     if (r <= sz  && h[r].val > h[largest].val){
          largest = r;
     }
     if (largest != idx){
          Hnode temp;
          temp = h[idx];
          h[idx] = h[largest];
          h[largest] = temp;
          max_heapify(h, largest);
     }
}
Esempio n. 4
0
int ast_heap_verify(struct ast_heap *h)
{
	unsigned int i;

	for (i = 1; i <= (h->cur_len / 2); i++) {
		int l = left_node(i);
		int r = right_node(i);

		if (l <= h->cur_len) {
			if (h->cmp_fn(heap_get(h, i), heap_get(h, l)) < 0) {
				return -1;
			}
		}

		if (r <= h->cur_len) {
			if (h->cmp_fn(heap_get(h, i), heap_get(h, r)) < 0) {
				return -1;
			}
		}
	}

	return 0;
}