Exemplo n.º 1
0
void *pqueue_dequeue(struct pqueue *queue)
{
	void *data = queue->array[0];
	queue->array[0] = queue->array[--queue->size];
	trickle_down(0, queue);
	return data;
}
Exemplo n.º 2
0
void pqueue_remove_at(int index, struct pqueue *queue)
{
	queue->array[index] = queue->array[--queue->size];

	if (index > 0
	    && (*queue->cmp)(queue->array[index],
			     queue->array[PARENT_OF(index)])
		       < 0) {
		trickle_up(index, queue);
	} else {
		trickle_down(index, queue);
	}
}
Exemplo n.º 3
0
void*
heap_pop(struct heap* h) {
    assert(h != NULL);
    ASSERT_HEAP(h);
    if (h->vals->num == 0)
        return NULL;
    void* top = array_get(h->vals, 0);
    void* last = array_get(h->vals, h->vals->num - 1);
    array_set(h->vals, 0, last);
    --h->vals->num;
    trickle_down(h, 0);
    /* TODO: array does not yet support shrinking */
    return top;
}