void build_max_heap_up(vector<T>& A) {
     // [0, heap_size) [heap_size, size)
     size_t heap_size = 1;
     while(heap_size < A.size()) {
         heapify_up(A, heap_size);
         heap_size++;
     }
 }
Exemplo n.º 2
0
Arquivo: heap.c Projeto: vdt/libcore
/* Complexity: O(log n), worst-case */
int heap_push(Heap *heap, void *data)
{
    assert(heap != NULL);

    darray_append(heap->h, data);
    heapify_up(heap, darray_size(heap->h) - 1);

    return 0;
}
Exemplo n.º 3
0
static void heapify_up(key_t * vec, size_t pos)
{
    /* daca am ajuns in radacina sau daca
       este respectata proprietatea */
    if (!pos || vec[pos].priority >=
                vec[PARENT(pos)].priority)
        return; // proprietate restabilita
    // trebuie sa "urcam" elementul
    swap(&vec[pos], &vec[PARENT(pos)]);
    heapify_up(vec, PARENT(pos));
}
Exemplo n.º 4
0
void pqueue_push(pqueue_t * pqueue, key_t key)
{
    // verificam daca incape in memorie
    if (pqueue->size + 1 > pqueue->capacity)
        // extindem vectorul
        pqueue->vec = (key_t *)realloc(pqueue->vec,
        sizeof(key_t) * (pqueue->capacity *= 2));
    if (!pqueue->vec)
        exit(EXIT_FAILURE);
    pqueue->vec[pqueue->size++] = key;
    // acum trebuie sa mentinem proprietatea de heap
    heapify_up(pqueue->vec, pqueue->size - 1);
}
Exemplo n.º 5
0
Arquivo: world.c Projeto: cmr/iiag
void schedule(action * act, long step) {
	action_node * a;

	if (world.acts_cnt == world.acts_alloc) {
		world.acts_alloc *= 2;
		world.acts = realloc(world.acts, world.acts_alloc * sizeof(action_node));
	}

	a = world.acts + world.acts_cnt;
	a->step = step + world.step;
	a->act = act;

	heapify_up(world.acts_cnt++);
}
Exemplo n.º 6
0
Arquivo: world.c Projeto: cmr/iiag
static void heapify_up(int i) {
	action_node * n;
	action_node * p;

	if (i) {
		n = world.acts + i;
		p = world.acts + (i - 1) / 2; // get the parent

		if (compare(n, p)) {
			swap(n, p);
			heapify_up(p - world.acts);
		}
	}
}
Exemplo n.º 7
0
void heapify_up(int arr[],int c)
{
	if(c > 0)
	{
		if(arr[parent(c)] < arr[c])
		{
			int tmp;
			tmp = arr[parent(c)];
			arr[parent(c)] = arr[c];
			arr[c] = tmp;
		}
		heapify_up(arr,parent(c));
	}
}
implicit_node* pq_insert( implicit_heap *queue, item_type item, key_type key )
{
    implicit_node *node = pq_alloc_node( queue->map, 0 );
    ITEM_ASSIGN( node->item, item );
    node->key = key;
    node->index = queue->size++;

#ifndef USE_EAGER
    if( queue->size == queue->capacity )
        grow_heap( queue );
#endif
    queue->nodes[node->index] = node;
    heapify_up( queue, node );

    return node;
}
void pq_decrease_key( implicit_heap *queue, implicit_node *node,
    key_type new_key )
{
    node->key = new_key;
    heapify_up( queue, node );
}
Exemplo n.º 10
0
void Heap_insert(void* val, Heap_T heap)
{
  assert(heap->index < heap->size );
  heap->array[heap->index] = val;
  heapify_up(heap, heap->index++);
}
Exemplo n.º 11
0
void heap_insert(int arr[],int n,int num)
{
	arr[n] = num;
	heapify_up(arr,n);
}