예제 #1
0
파일: heap.cpp 프로젝트: cbm755/inpaintBCT
void Heap::insert(hItem item)
{
    int index;
    
    index = item.j * pdata->rows + item.i;
    
	if(item.flag == BAND)
	{
		if(item.hpos == -1) // not yet in heap
		{
			// T update and heap insertion
			pdata->Tfield[index].T = item.T;
			size = size + 1;
			pdata->Tfield[index].hpos = size;
			heap[size] = &(pdata->Tfield[index]);
			upHeap(size);

		}
		else // already in heap
		{
			// only T update
			double oldT = heap[item.hpos]->T;
			heap[item.hpos]->T = item.T;

			if(oldT > item.T)
				upHeap(item.hpos);
			else
				downHeap(item.hpos);
		}
	}
}
예제 #2
0
파일: heap.c 프로젝트: finchd/heap.c
int main (int argc, char *argv[]){
  int heapItems = 0;
  int heapSize = 16;
  int minHeap[heapSize];
  
  int upHeap(int x){ //TODO build upHeap
    if(x == 1) {
      return 0; // if we are at the root, stop
    }
    
    if(minHeap[parent(x)] <= minHeap[x]) {
      return 0; //already satisfy heap-invariant for min-heap
    }
      
    // swap x and parent(x)
    int temp = minHeap[x];
    minHeap[x] = minHeap[parent(x)];
    minHeap[parent(x)] = temp;
    
    upHeap(parent(x));
  
    return 0;
  }
  
  int add(int value){
    if( heapItems == 0) { // We're empty
      minHeap[1] = value;
      ++heapItems;
      return 0;
    }
    if( (heapItems + 1) == heapSize ) { // We're full
      //TODO grow array
    }
  
    // default case, add to end and upheap
    ++heapItems;
    minHeap[heapItems] = value;
    upHeap(heapItems);
    return 0;
  }
  
  add(33);
  add(27);
  add(57);
  add(67);
  add(17);
  add(87);

  printf("[");
  int i = 1;
  for(; i <= heapItems; ++i) {
    printf("%d, ", minHeap[i]);
  }
  printf("]\n\n");

  exit(0);
}
예제 #3
0
void Heap :: update(double time, int Ind) {
    Keys [ T2H [ Ind ] ] = time;

    // Must do one upHead run because maybe this new, lower, time
    // is lower than those of the parents. By design of Fast-Marching
    // it should never be larger though.
    upHeap(T2H [ Ind ]);
}
예제 #4
0
void PriorityQueue::insert(QueueElement QE) {
	if(!contains(QE)) {
		PQ.push_back(QE);
		upHeap(PQ, PQ.size() - 1);
	}
	else
		chgPriority(QE);
}
예제 #5
0
파일: priority.c 프로젝트: ZosiaRog/WDI
void increaseKey(int old, int newkey, int *queue){
	if(newkey < queue[old]){
		printf("podaj większy klucz");
	} else {
		queue[old] = newkey;
		upHeap(old, queue);
	}
}
예제 #6
0
long PriorityQueue::insert (PQNode& item) {

	if (numItems == maxItems)
		return(1);

	pqList[++numItems] = item;
	upHeap(numItems);
	return(0);
}
예제 #7
0
파일: algo11.c 프로젝트: n071w0/algo
void upHeap(int array[],int n){
	int tmp;
	if(array[n]>array[n/2] && n>1){
		tmp=array[n];
		array[n]=array[n/2];
		array[n/2]=tmp;
		upHeap(array,n/2);
	}
}
예제 #8
0
/*
 * Update priority for a task in the queue
 */
void LpelTaskqueueUpdatePriority(taskqueue_t *tq, lpel_task_t *t, double np){
	int pos = searchItem(tq, t);
	assert(pos > 0);
	double p = t->sched_info.prior;
	t->sched_info.prior = np;
	if (np > p)
		upHeap(tq, pos);
	else if (np < p)
		downHeap(tq, pos);
}
예제 #9
0
파일: upHeap.c 프로젝트: ZosiaRog/WDI
void upHeap(int i) {
    int x;
    if (i!=0 && (Heap[parent(i)] < Heap[i])) {
        x = Heap[parent(i)];
        Heap[parent(i)] = Heap[i];
        Heap[i] = x;
        printf("rodzic %d ", parent(i));
        upHeap(parent(i));
    }
}
예제 #10
0
void PriorityQueue::change (long itemIndex, long newValue) {

	if (newValue > pqList[itemIndex].key) {
		pqList[itemIndex].key = newValue;
		downHeap(itemIndex);
		}
	else if (newValue < pqList[itemIndex].key) {
		pqList[itemIndex].key = newValue;
		upHeap(itemIndex);
	}
}
예제 #11
0
파일: upHeap.c 프로젝트: ZosiaRog/WDI
int main() {
    wczytaj();
    wypisz(size);
    kopcuj(size);
    wypisz(size);
    Heap[8]=100;
    upHeap(8);
    wypisz(size);

    return 0;
}
예제 #12
0
/*
 * Add a task to the task queue
 */
void LpelTaskqueuePush( taskqueue_t *tq, lpel_task_t *t){

  //allocate more memory if needed
  if (tq->count >= tq->alloc) {
    tq->alloc = tq->alloc + BLOCKSIZE;
    tq->heap = realloc(tq->heap, tq->alloc *sizeof(taskqueue_t*));
  }

  tq->heap[tq->count] = t;
  upHeap(tq, tq->count);
  tq->count++;
}
예제 #13
0
void PriorityQueue::chgPriority(QueueElement QE) {
	for(int i = 0; i < PQ.size(); i++)
		if(PQ[i].node == QE.node) {
			if(PQ[i].value > QE.value) {
				PQ[i].value = QE.value;
				upHeap(PQ, i);
			}
			else {
				PQ[i].value = QE.value;
				downHeap(PQ, i);
			}
			break;
		}
}
예제 #14
0
void Heap :: insert(double time, int Ind) {
    // Reallocate more memory if necessary
    if ( heapCount == ( allocatedSize - 1 ) ) {
        Keys = ( double * ) realloc( Keys,
                                     ( allocatedSize + Initial_Heap_Alloc_Size ) * sizeof( double ) );
        H2T  = ( int * )    realloc( H2T,
                                     ( allocatedSize + Initial_Heap_Alloc_Size ) * sizeof( int ) );
    }

    // Insert element at the end of the heap
    Keys [ heapCount ] = time;
    H2T [ heapCount ] = Ind;
    T2H [ Ind ] = heapCount;

    heapCount++;

    // Ensure the heap is maintained by moving the
    // new element as necessary upwards in the heap.
    upHeap(heapCount - 1);
}
예제 #15
0
파일: priority.c 프로젝트: ZosiaRog/WDI
void insert(int element, int *queue){
	queue[omega] = element;
	upHeap(omega, queue);
	omega++;
//	printf("q = %d o = %d\n", queue[omega-1], omega);
}