Example #1
0
graph kruskal(graph G, float (*pesoArco )(void *)) {
    int         nNodes  = graphCountNodes(G);
    graph       GF       = graphInit(nNodes, GRAPH_IS_NOT_ORIENTED); // e gli orientati??
    uf_handler  uf      = uf_init(graphGetMaxNodes(G));

    archInfo arco;

    coda allArcs=graphGetAllArchs(G);
    heap archHeap=heapInit(nNodes, pesoArco, HEAP_GET_MIN);

    while ((arco=codaGet(allArcs))!=NULL) {
        heapInsert(archHeap, arco);
    }

    int from, to;

    while ((arco= heapExtract(archHeap))!=NULL) {
        from=arco->fromNode;
        to= arco->toNode;

        if (uf_find(uf,from , to)) {
            uf_unionFind(uf, from, to);

            graphAddNode(GF, from, arco->fromInfo);
            graphAddNode(GF, to, arco->toInfo);
            graphAddArch(GF, from, to, arco->archInfo);
        }
    }

    return GF;

}
Example #2
0
static int structTest(void)
{
  struct SmallTestStruct_t {
    uint16_t member1;
    uint16_t member2;
    uint32_t member3;
  };
  struct LargeTestStruct_t {
    uint32_t member1;
    uint32_t member2;
    uint32_t member3;
    uint32_t member4;
  };

  // Make sure the small test struct warrants a small buffer (8 bytes)
  // and the large struct warrants a large buffer (32 bytes).
  expectEquals(sizeof(struct SmallTestStruct_t), 8);
  expectEquals(sizeof(struct LargeTestStruct_t), 16);

  heapInit();  

  // Allocate memory for a small struct and make sure it functions properly.
  struct SmallTestStruct_t *smallStructPointer
    = (struct SmallTestStruct_t *)
      heapAlloc(sizeof(struct SmallTestStruct_t));
  struct SmallTestStruct_t smallStruct;
  expect(smallStructPointer != NULL);
  smallStructPointer->member1 = 1;
  smallStructPointer->member2 = 2;
  smallStructPointer->member3 = 3;
  expectEquals(smallStructPointer->member1, 1);
  expectEquals(smallStructPointer->member2, 2);
  expectEquals(smallStructPointer->member3, 3);
  anmatMemcpy(&smallStruct, smallStructPointer, sizeof(struct SmallTestStruct_t));
  expectEquals(smallStruct.member1, 1);
  expectEquals(smallStruct.member2, 2);
  expectEquals(smallStruct.member3, 3);

  // Same thing with a large struct.
  struct LargeTestStruct_t *largeStructPointer
    = (struct LargeTestStruct_t *)
      heapAlloc(sizeof(struct LargeTestStruct_t));
  struct LargeTestStruct_t largeStruct;
  expect(largeStructPointer != NULL);
  largeStructPointer->member1 = 1;
  largeStructPointer->member2 = 2;
  largeStructPointer->member3 = 3;
  largeStructPointer->member4 = 4;
  expectEquals(largeStructPointer->member1, 1);
  expectEquals(largeStructPointer->member2, 2);
  expectEquals(largeStructPointer->member3, 3);
  expectEquals(largeStructPointer->member4, 4);
  anmatMemcpy(&largeStruct, largeStructPointer, sizeof(struct LargeTestStruct_t));
  expectEquals(largeStruct.member1, 1);
  expectEquals(largeStruct.member2, 2);
  expectEquals(largeStruct.member3, 3);
  expectEquals(largeStruct.member4, 4);

  return 0;
}
Example #3
0
PED* peInit(int msx, int msy, int iMaxRequests, int iHeapSize, int iMPCPT, int iMaxWalkers )
{
  PED* PE;
  PE = (PED*)malloc(sizeof(PED));
  if (!PE) return NULL;
  
  PE->Time = 0;
  if (!peInitMap(PE, msx, msy))                   goto error;
  if (!peInitRequests(PE, iMaxRequests+1, iMPCPT+1))  goto error;
  if (!peInitPaths(PE, 5000))                     goto error;
  if (!peInitWalkers(PE, iMaxWalkers))            goto error;
  if (!(PE->Open = heapInit(iHeapSize)))          goto error;
  
  PE->HeapSize = iHeapSize; 
  PE->LastSID = 0;
  peSetHeuristics(PE, &HeuristicsMax);
  peSetMixFunction(PE, &MixAStar);
  peSetMixCoef(PE, 0.5);  // just for sure, Coef1 is not out of boundaries
  peSetSettings(PE, PC_MAXTC, PC_STANDING_BLOCKER_COST, PC_WALKING_BLOCKER_COST, PC_STEP_COST,
    PC_BASE_COST, PC_BASE_COST1, PC_BASE_COST2, PC_NEAR_DESTINATION, PC_BADFINALRATIO,
    PC_BADSHIFT, PC_FSBEHIND, PC_WAITING_TIMEOUT, PC_DEADLOCK_TIMEOUT);
  PE->State = 0;
  return PE;
  
error:
  if (PE) peDone(PE);
  return NULL;
}
int main(int argc, char* argv[])
{
	int T, N;

	scanf("%d", &T);

	for (int test_case = 1; test_case <= T; test_case++)
	{
		scanf("%d", &N);
		
		heapInit();
		
		for (int i = 0; i < N; i++)
		{
			int value;
			scanf("%d", &value);
			heapPush(value);
		}

		printf("#%d ", test_case);

		for (int i = 0; i < N; i++)
		{
			int value;
			heapPop(&value);
			printf("%d ", value);
		}
		printf("\n");
	}
	return 0;
}
Example #5
0
void APP_vMain (void)
{
	heapInit();
	os_malloc_completed = 1;
	os_init_completed = 1;
	printf("MINIOS:Start test----\n");	
	os_TaskCreate(TaskStart, 
				(void *)0, 
				(void *)&TaskStartStk[TASK_STK_SIZE - 1], 
				TASK_START_PRIO);
	
	os_SystemStart();                              /* Start multitasking */
	
	while(1);
}
Example #6
0
int main()
{
	int i,n,x;
	heap *p=NULL;
	p=heapAlloc();
	scanf("%d",&n);
	heapInit(p,sizeof(int),n+1,gt);
	for(i=0;i<n/2;i++)
	{
		x=i+n/2;
		heapPush(p,&x);
	}
	for(i=0;i<n/2;i++)
		heapPush(p,&i);
	while(!heapEmpty(p))
	{
		heapPop(p,&x);
		printf("%d%c",x,heapEmpty(p)?'\n':' ');
	}
	return 0;
}
Example #7
0
static int stressTest(void)
{
  unsigned char *pointers[3] = {NULL, NULL, NULL,};

  // Initializing the heap should mean all the bytes are available.
  heapInit();
  expectHeapEmpty();
  
  // Let's allocate the whole heap with two chunks. One will be
  // (HEAP_SIZE / 4 - 1) bytes and the other will be
  // ((3 * HEAP_SIZE / 4) - 1) bytes.
  pointers[0] = (unsigned char *)heapAlloc((HEAP_SIZE / 4) - 1); 
  expect(pointers[0] != NULL);
  pointers[1] = (unsigned char *)heapAlloc(((3 * HEAP_SIZE) / 4) - 1); 
  expect(pointers[1] != NULL);

  // There should be no bytes left.
  expectHeapFull();

  // Therefore, we should not be able to allocate anymore.
  pointers[2] = (unsigned char *)heapAlloc(1);
  expect(pointers[2] == NULL);

  // If we free the first guy, we should only be missing the second big chunk.
  heapFree(pointers[0]);
  expectHeapSize(HEAP_SIZE - (((3 * HEAP_SIZE) / 4) - 1) - 1);
  
  // If we try to allocate some memory that is equal to the bytes left,
  // then we should fail, because we need any extra byte to mark the end of
  // the reference.
  pointers[2] = heapAlloc(heapFreeBytesCount);
  expect(pointers[2] == NULL);

  // Make sure when we free the second chunk, we have a full heap available.
  heapFree(pointers[1]);
  expectHeapEmpty();

  return 0;
}
Example #8
0
static int arrayTest(void)
{
  int **matrix, i;

  heapInit();
  expectHeapEmpty();

  // Allocate room for 3 pointers.
  matrix = (int **)heapAlloc(3 * sizeof(int *));
  expectHeapSize(HEAP_SIZE
                 - (3 * (sizeof(int *))) - 1 // 3 pointers and 1 alloc byte
                 - 0);
  
  // Allocate 5 integers in each array.
  for (i = 0; i < 3; i ++) {
    matrix[i] = (int *)heapAlloc(5 * sizeof(int));
  }
  expectHeapSize(HEAP_SIZE
                 // 3 pointers and 1 alloc byte
                 - (3 * (sizeof(int *))) - 1
                 // 3 arrays of 5 int's plus an alloc byte each
                 - 3 * ((5 * sizeof(int)) + 1) 
                 - 0);

  // Free the arrays.
  for (i = 0; i < 3; i ++) {
    heapFree(matrix[i]);
  }
  expectHeapSize(HEAP_SIZE
                 - (3 * (sizeof(int *))) - 1 // 3 pointers and 1 alloc byte
                 - 0);
  
  // Free the pointers.
  heapFree(matrix);
  expectHeapEmpty();

  return 0;
}
Example #9
0
int main () {
  initCoCoSupport();
  heapInit();
  timeInit();
  setHighSpeed(TRUE);
  width(32);

  if (dateTime->marker = 0x1234) {
    timeSet(dateTime->year, dateTime->month, dateTime->day, dateTime->hour,
            dateTime->minute, dateTime->second);
  }

  daliConfig.width = 256;
  daliConfig.height = 192;
  daliConfig.bitmap = 0xe00;
  daliConfig.max_fps = 30;
  daliConfig.max_cps = 30;
  daliConfig.render_state = 0;
  daliConfig.time_mode = HHMMSS;
  daliConfig.date_mode = MMDDYY;
  daliConfig.display_date_p = 0;
  daliConfig.test_hack = 0;

  render_init(&daliConfig);
  memset(daliConfig.bitmap, 0xff, 6144);
  pmode(4, daliConfig.bitmap);
  screen(1, 1);

  UInt32 displayTimeTime;
  UInt32 five = UInt32Init(0, 5);
  struct timeval now;
  struct timezone tzp;

  while(TRUE) {
    // Revert to time display if time
    if (daliConfig.display_date_p) {
      gettimeofday(&now, &tzp);
      if (UInt32GreaterThan(&now.tv_sec, &displayTimeTime)) {
        daliConfig.display_date_p = FALSE;
      }
    }

    byte a = MyInkey();
    switch(a) {
      case '0':
        daliConfig.time_mode = HHMMSS;
        daliConfig.date_mode = MMDDYY;
        break;

      case '1':
        daliConfig.time_mode = HHMMSS;
        break;

      case '2':
        daliConfig.time_mode = HHMM;
        break;

      case '3':
        daliConfig.time_mode = SS;
        break;

      case '4':
        daliConfig.date_mode = MMDDYY;
        break;

      case '5':
        daliConfig.date_mode = DDMMYY;
        break;

      case '6':
        daliConfig.date_mode = YYMMDD;
        break;

      case ' ':
        daliConfig.display_date_p = TRUE;
        gettimeofday(&now, &tzp);
        UInt32Add(&displayTimeTime, &now.tv_sec, &five);
        break;
    }

    render_once(&daliConfig);
  }

  return 0;
}