Ejemplo n.º 1
0
void testList()
{
  list mylist;
  mylist.head = 0x0;
  mylist.count = 0;
  mylist.current = 0x0;
  int i= 0;
  
  addToSortedList(&mylist, 1804289383);
  addToSortedList(&mylist, 846930886);
  searchList( &mylist, 846930886);
  list temp;
  copyList( &temp, &mylist);
  searchList(&temp, 846930886);
  for( i = 0; i <= 2000; i ++)
    {
      int x = rand();
      addToSortedList(&mylist, x);
      list temp;
      copyList(&temp,& mylist);
      if(!searchList( &mylist, x) || !searchList(&temp, x))
	{
	  printf ("\nERROR %d \n", x);
	  i = 2001;
	}
      else 
	{
	  printf("%d\t", x);
	}
      deleteList(& temp, blanko);
    }
}
Ejemplo n.º 2
0
void getPolinomial(IntList *p)
{
	int x = 0; //pow
	int k = 0; //factor

	deleteList(p->next);
	p->next = NULL;

	while (true)
	{
		scanf("%d %d", &x, &k);
		if (!k)
			break;
		addToSortedList(p, x, k);
	}
}
Ejemplo n.º 3
0
int _tmain(int argc, _TCHAR* argv[])
{
	printf("0 - exit\n");
    printf("1 - add value to sorted list\n");
    printf("2 - remove value from list\n");
    printf("3 - print list\n");

	IntList *head = newList(-1);

	while(true)
	{
		printf("Input command:\n");
		int command = 0;
		scanf("%d", &command);
		int val = 0;
		switch (command)
		{
			case 0:
				deleteList(head);
				return 0;
			case 1:
				printf("Input value:\n");
				
				scanf("%d", &val);
				addToSortedList(head, val);
				break;
			case 2:
				printf("Input value:\n");
				
				scanf("%d", &val);
				removeValue(head, val);
				break;
			case 3:
				printList(head);
				break;
		};

	}
	
	deleteList(head);

	scanf("%*s");
	return 0;
}
Ejemplo n.º 4
0
/*
void test3( )
{

  sibgroupsmap = (struct hashtable *) create_hashtable(100, sibgroupHash, sibgroupEquals); 
  int i =0, j =0;
  int max = 100;
  nloci = 5;
  init();
  for(i = 0; i < max; i ++)
    {
      sibgroup * group= malloc(sizeof(sibgroup));
      initializeSibgroup(group);
      for(j =0; j < nloci; j ++)
	{
	  int k = 0;

	  printf("locus %d\n", j);
	  //	  for(k=1; k < MAX_ALLELES_PER_LOCUS; k ++)
	    {
	      int * key1 = malloc(sizeof(int));
	      int * value1 =malloc(sizeof(int));
	      *key1 = rand() % 400;
	      *value1 = k++;
	      hashtable_insert( group->intmaps[j] , key1, value1);
	      printf("%d -> %d\t", *key1, *value1);

	      int * key2 = malloc(sizeof(int));
	      int * value2 =malloc(sizeof(int));
	      *key2 = rand() % 400;
	      *value2 = k++;
	      hashtable_insert( group->intmaps[j] , key2, value2);
	      printf("%d -> %d\t", *key2, *value2);

	      int * key3 = malloc(sizeof(int));
	      int * value3 =malloc(sizeof(int));
	      *key3 = rand() % 400;
	      *value3 = k++;
	      hashtable_insert( group->intmaps[j] , key3, value3);
	      printf("%d -> %d\t", *key3, *value3);

	      int * key4 = malloc(sizeof(int));
	      int * value4 =malloc(sizeof(int));
	      *key4 = rand() % 400;
	      *value4 = k++;
	      hashtable_insert( group->intmaps[j] , key4, value4);
	      printf("%d -> %d\n", *key4, *value4);
	    }
	  
	  int a1 = rand() % 10;
	  int a2 = rand() % 10;
	  int a3 = rand() % 10;
	  int a4 = rand() % 10;
      
	  group->possibilitysets[j][a1] =1;      
	  group->possibilitysets[j][a2] =1;      
	  group->possibilitysets[j][a3] =1;
	  group->possibilitysets[j][a4] =1;
	  
	  group->mutate = i;
	  
	  
	  

	}

      
      hashtable_insert(sibgroupsmap, group, group);
      sibgroup * fish ;
      if((fish = hashtable_search(sibgroupsmap, group)) == NULL || fish->mutate != i)
	{
	  hashtable_search(sibgroupsmap, group);
	  printf("ERRORRRRR\n");
	}
    }
}

void test( )
{
  long i;
  while (1)
    {
      sibgroup * test = malloc(sizeof(sibgroup));
      initializeSibgroup(test);
      sibgroup * copy = copySibgroup(test);
      deleteSibgroup(test);
      deleteSibgroup(copy);
      
    }
}


void test2()
{

  //  test();
  init();
  dolog = 1;
  nloci = 2;
  readPossibilities("siblings-complete.csv");
  readData("mixednuts.csv");

  reconstruct();
  writeResultsFile("blah");

}
*/
void testparallel()
{

  individuals = 50;
  data.count = 50;
  int i;
  list listy;
  listy.head = NULL;
  listy.count = 0;
  listy.current = NULL;
  for(i = 0; i < individuals; i ++)
    {
      addToSortedList(&listy, i);
    }

  blocks = 2;
  unsigned int * coded = encodeList(&listy);
  printf("Coded val for first block = %X, second block = %X\nMax Value for unsigned int %X\n", coded[0],coded[1],UINT_MAX);

  list listy2;
  listy2.head = NULL;
  listy2.count = 0;
  listy2.current = NULL;
  addToSortedList(&listy2, 5);
  addToSortedList(&listy2, 4);
  addToSortedList(&listy2, 7);
  addToSortedList(&listy2, 45);


  unsigned int * coded2 = encodeList(&listy2);
  printf("Coded val for first block= %X\tsecond block %X\n", coded2[0], coded2[1]);

  list listy3;
  listy3.head=NULL;
  listy3.current = NULL;
  listy3.count = 0;
  addToList(&listy3, coded);

  list listy4;
  listy4.head=NULL;
  listy4.current = NULL;
  listy4.count = 0;
  addToList(&listy4, coded2);



  list listy6;
  listy6.head = NULL;
  listy6.count = 0;
  listy6.current = NULL;
  addToSortedList(&listy6, 5);
  addToSortedList(&listy6, 14);
  addToSortedList(&listy6, 7);
  addToSortedList(&listy6, 41);


  list listy7;
  listy7.head = NULL;
  listy7.count = 0;
  listy7.current = NULL;
  addToSortedList(&listy7, 5);
  addToSortedList(&listy7, 14);
  addToSortedList(&listy7, 7);
  addToSortedList(&listy7, 41);

  
  unsigned int * coded3 = encodeList(&listy6);
  addToList(&listy4, coded3);
  writeResultsFileList("listy4", &listy4);
  intersectsibgroups(&listy4, &listy3);

  unsigned int * x = (unsigned int *) listy4.head->data;
  printf("Coded val for first block= %X\tsecond block %X\nequals %d", x[0],x[1],equalsArray(x,coded2,0xDEADBEEF) );
  writeResultsFileList("listy3", &listy3);
  writeResultsFileList("listy4-2", &listy4);
  


  return;

  //void intersectsibgroups(list * currentList, list * sibgroupslist)
  /* list  x;
  x.head = NULL;
  x.count = 0;
  x.current = NULL;
  
  list y;
  y.head = NULL;
  y.count = 0;
  y.current = NULL;

  list z;
  z.head = NULL;
  z.count = 0;
  z.current = NULL;


  list alpha;
  alpha.head = NULL;
  alpha.count = 0;
  alpha.current = NULL;
  
  list beta;
  beta.head = NULL;
  beta.count = 0;
  beta.current= NULL;
  
  individuals = 6;
  data.count = 6;

  addToSortedList(&x, 1);
  addToSortedList(&x, 2);
  addToSortedList(&x, 4);

  addToSortedList(&y, 1);
  addToSortedList(&y, 3);
  addToSortedList(&y, 5);

  addToSortedList(&z, 1);
  addToSortedList(&z, 4);
  addToSortedList(&z, 5);


 unsigned int * x1=  encodeList(&x);
 unsigned int * y1= encodeList(&y);
 unsigned int * z1= encodeList( &z);

 printf("x1=%d y1=%d z1=%d\n", *x1, *y1, *z1);

  addToList(&alpha, x1);

  addToList(&alpha, z1);
  addToList(&beta, y1);

  intersectsibgroups(&beta, &alpha);

  

   if( NULL == (dumpfile = fopen( "dump", "w")))
        {
          printf("Unable to write results\n");
          exit(-1);
        }
   writeResultsFileList("dump", &beta);
*/  

  nloci =2;
  // APR - passing nloci, not sure what goes here as init() doesn't exist
  init(nloci);
  readPossibilities("siblings-complete.csv");
  readData("juv_test1");
   list * finallist = lociConstruct("juv_test1", 2);
  // writeResultsFileList("dump", finallist);
   if( NULL == (dumpfile = fopen( "dump", "w")))
        {
          printf("Unable to write results\n");
          exit(-1);
        }
   writeResultsFileList("dump", finallist);
  
}