Пример #1
0
Test* scavengeWeakNoExists(){
    Test* t = createTest();
    int* data = malloc(sizeof(int)); *data = 0;
    heapAdd(t->h, INT, inn);
    heapAdd(t->h, WEAK, data);

    push(&(t->s), 2);
    return t;
}
Пример #2
0
Test* testPhantom(){
    Test* t = createTest();
    int data[] = { 0,1 };
    heapAdd(t->h,PHANTOM,data);
    int data1[] = { 0,0 };
    heapAdd(t->h,PHANTOM,data1);
    push(&(t->s),0);
    return t;
}
Пример #3
0
Test* scavengePhantomNoFinal(){
    Test* t = createTest();
    int data[] = { 0,1 };

    heapAdd(t->h, INT, inn);
    heapAdd(t->h, PHANTOM, data);

    push(&(t->s), 2);
    return t;
}
Пример #4
0
Test* testBool(){
    Test* t = createTest();
    int* data = malloc(sizeof(int)); *data = 0;
    heapAdd(t->h,BOOL,data);
    data = malloc(sizeof(int)); *data = 1;
    heapAdd(t->h,BOOL,data);
    push(&(t->s),0);
    push(&(t->s),2);
    return t;
}
Пример #5
0
Test* scavengeLambda(){
    Test* t = createTest();

    int data[] = {0,2,0,2};
    heapAdd(t->h, INT, inn);
    heapAdd(t->h, BOOL, boo);
    heapAdd(t->h, LAMBDA, data);

    push(&(t->s),4);
    return t;   
}
Пример #6
0
Test* scavengeRange(){
    Test* t = createTest();

    int data[] = { 0, 5};
    heapAdd(t->h, INT, inn);
    heapAdd(t->h, RANGE, data);
    heapAdd(t->h, STRING, str);

    push(&(t->s),2);
    return t;
}
Пример #7
0
Test* scavengeBD(){
    Test* t = createTest();

    int data[] = {2,0,0,2};
    heapAdd(t->h, INT, inn);
    heapAdd(t->h, BOOL, boo);
    heapAdd(t->h, BIGDATA, data);

    push(&(t->s),4);
    return t;
}
Пример #8
0
Test* bigdatanocoll(){
    Test* t = createTest();
    push(&(t->s),0);

    collectioncount = 1;
    int bigdata[] = { 3,1,0,0,0 };
    
    //build test heap
    heap* h = t->h;
    heapAdd(h,BIGDATA,bigdata);
    heapAdd(h,BIGDATA,bigdata);

    return t;
}
Пример #9
0
 inline void heapAdjustOrAdd (Heap &heap) {
   typename Heap::iterator heapLoc = location();
   if (heapLoc)
     heapAdjustUp(heap.begin(), heapLoc);
   else
     heapAdd(heap, *this);
 }
Пример #10
0
Test* testWeak(){
    Test* t = createTest();
    int* data = malloc(sizeof(int)); *data = 0;
    heapAdd(t->h,WEAK,data);
    push(&(t->s),0);
    return t;
}
Пример #11
0
Test* testLambda(){
    Test* t = createTest();
    int data[] = { 0, 2, 0, 0 };
    heapAdd(t->h,LAMBDA,data);
    push(&(t->s),0);
    return t;
}
Пример #12
0
Test* testRange(){
    Test* t = createTest();
    int data[] = { 0, 0 };
    heapAdd(t->h,RANGE,data);
    push(&(t->s),0);
    return t;
}
Пример #13
0
Test* testBigdata(){
    Test* t = createTest();
    int data[] = { 2, 0, 0, 0 };
    heapAdd(t->h,BIGDATA,data);
    push(&(t->s),0);
    return t;
}
Пример #14
0
Test* testString(){
    Test* t = createTest();
    char* data = "hello";
    heapAdd(t->h,STRING,data);
    push(&(t->s),0);
    return t;
}
Пример #15
0
Test* testInt(){
    Test* t = createTest();
    int* data = malloc(sizeof(int)); *data = 5;
    heapAdd(t->h,INT,data);
    push(&(t->s),0);
    return t;
}
Пример #16
0
int huffmanWeight(Tree** heap, int n) {
    heapify(heap, n);
    while(n > 1) {
        Tree* huff =createHuffmanNode();
        huff->left = heapDelete(heap, n--);
        huff->right = heapDelete(heap, n--);
        huff->weight = huff->left->weight + huff->right->weight;
        heapAdd(heap, n++, huff);
    }
    
    return weighting(heap[0]);
}
Пример #17
0
int main() {
	int i;
	srand(time(NULL));
	Heap * h = createHeap(100);
	for (i = 0; i < 100; ++i) {
		if (i > 20) {
			heapAdd(h, createHeapNode(FLT_MAX, i));
			continue;
		}
		heapAdd(h, createHeapNode(rand() % 100, i));
	}

	displayHeap(h);
	for (i = 0; i < 10; ++i) {
		HeapNode *tmp = heapExtractHead(h);

		fprintf(stdout, "\nAncien noeud : ");
		displayHeapNode(tmp);
		fprintf(stdout, "\n");
		tmp->c = rand() * i % 100 + 100;
		fprintf(stdout, "Nouveau noeud : ");
		displayHeapNode(tmp);

		heapAdd(h, tmp);

		displayHeap(h);
	}

	HeapNode * tmp = heapExtract(h, 2);
	tmp->c = rand() % 100;

	heapAdd(h, tmp);

	displayHeap(h);

	freeHeap(h);

	return 0;
}
Пример #18
0
void testComp(int i){
    Test* t = createTest();
    int j;
    int* r = malloc(sizeof(int)*2);
    r[0] = 0;
    for(j=0; j<i; j++){
        r[1] = (j+1)*3;
        heapAdd(t->h,RANGE,r);
    }
    //simplePrintHeap(t->h);
    push(&(t->s),0);
    collect(t->s, &(t->h), 0);
}
Пример #19
0
void
updateTime(Block* block, Time ts, int delta)
{
  fprintf(stderr, "Updatetime: %d <- %d was:%d, %d\n", block->id, ts, block->localTime, block->lastSimTime);
  if (block->localTime <= ts) {
    block->localTime = ts;
    if (heapUpdate(gheap, block) == NULL) {
      heapAdd(gheap, block);
    }
  }
  Block* minBlock = (Block*)heapPeek(gheap);
  if (minBlock->localTime > globalTimeStamp) 
    globalTimeStamp = minBlock->localTime;
}
Пример #20
0
int peFindPathWW(PED* PE, MapNode* Start, MapNode* End, peTime StartTime, int Speed, PathStep** path)
{
  MapNode* v = Start;
  MapNode* s;
  MapNode* best = Start;
  int i;
  int BaseCost;
  int c,z;
  
  if (Start == End) return 0;
  
  PE->LastSID++;
  heapClear(PE->Open);
  
  v->g = 0;
  v->f = 0;
  v->h = (*PE->Heuristics)(PE, v, End);
  v->Steps = 0;
  v->Time = 0;
  heapAdd(PE->Open, v);
  
  while ((v != End) && (PE->Open->ActSize!=0))
  {
#ifdef PE_MONITOR  // pro monitorovani enginu
    peENodes++;
#endif
    
    v = PE->Open->HeapBuffer[1];
    heapRemove(PE->Open, v);
    
    // best position is the closest to the dest
    // and the most distanced from the start
    if ((v->h<best->h) || (v->h=best->h) && (v->g>best->g)) best = v; 
    
    for (i=0; i<8; i++)
    {
      s = peMapXY(PE, v->Pos.X+Dir2Delta[i][0], v->Pos.Y+Dir2Delta[i][1]); // s = sousedni policko
      if ((!s) || (s->TC==PE->MAXTC) || (s->Owner!=-1)) continue;
      if (s->SearchID == PE->LastSID)
      {
        if (s->HeapPos>0)
        {
          if (DirType[i]==0)
            BaseCost = PE->HorizontalCost;
          else
            BaseCost = PE->DiagonalCost;
          c = v->g + BaseCost;
          z = v->FootSteps;
          
          if (c + z < s->g)
          {
            s->h = (*PE->Heuristics)(PE, s, End);
            s->Steps = v->Steps + 1;
            s->Time = v->Time + Speed;
            s->f = (*PE->MixFunction)(PE, c, s->h, z);
            s->g = c + z;
            s->CameFrom = v->Pos;
            heapSiftUp(PE->Open, s->HeapPos);
          }
        }
        // else konecny
      } 
      else
      {
        s->SearchID = PE->LastSID;
        if (DirType[i]==0)
          BaseCost = PE->HorizontalCost;
        else
          BaseCost = PE->DiagonalCost;
        
        c = v->g + BaseCost;
        z = v->FootSteps;
        
        s->h = (*PE->Heuristics)(PE, s, End);
        s->Steps = v->Steps + 1;
        s->Time = v->Time + Speed;
        s->f = (*PE->MixFunction)(PE, c, s->h, z);
        s->g = c + z;
        s->CameFrom = v->Pos;
        if (heapAdd(PE->Open, s)==HP_NOSPACE)
        {
          // we ran out off free heap space
          // get the best known position and continue
          // after walker reaches this position
          End = best;
          v = best;
          break;
        }
      }
    }
  }
  if (Start == End) return 0;
  if (v!=End) return 0;
  if (!peAddPath(PE, path, End->Steps+1)) return 0;
  
  i=v->Steps+1;
  while (i>0)
  {
    i--;
    (*path)[i].Time = StartTime + v->Time;
    (*path)[i].Type = PST_CONTINUE | PST_FOOTSTEP;
    (*path)[i].Pos = v->Pos;
    v->FootSteps+=PE->FootStepCost;
    
    v=peMapXY(PE, v->CameFrom.X, v->CameFrom.Y);
  }
  
  (*path)[End->Steps].Type = PST_END | PST_FOOTSTEP;
  
  return End->Steps+1;
}
Пример #21
0
Test* test2(){
    Test* t = createTest();
    push(&(t->s),24);
    push(&(t->s),13);
    push(&(t->s),0);

    collectioncount = 2;
    int data[] = { 2,4,28 };
    int bigdata[] = { 3,1,19,21,2 };
    int range[] = { 0,32 };
    int lambda[] = { 8,1,6 };
    int phantom[] = { 4,1 };
    int* soft = malloc(sizeof(int));
    *soft = 0;
    int* weak = malloc(sizeof(int));
    *weak = 2;

    //build test heap
    heap* h = t->h;
    heapAdd(h,INT,inn);
    heapAdd(h,BOOL,boo);
    heapAdd(h,WEAK,weak);
    heapAdd(h,STRING,str);
    heapAdd(h,BIGDATA,bigdata);
    heapAdd(h,LAMBDA,lambda);
    heapAdd(h,INT,inn);
    heapAdd(h,RANGE,range);
    heapAdd(h,DATA,data);
    heapAdd(h,SOFT,soft);
    heapAdd(h,BIGDATA,bigdata);
    heapAdd(h,PHANTOM,phantom);

    return t;
}