Пример #1
0
void Seeker::seekPermutations()
{
	unsigned long long int N = 0;
	double duration, start = clock();
	unsigned long long int TOTAL = countTotal(_v, _kp, _km);
	bool isFound = false;
	while (_sequence[0] != 2)
	{
		N++;
		duration = (clock() - start) / (double)CLOCKS_PER_SEC;
		if (duration > SHOW_TIME)
		{
			cout << "Done: " << (N*100.)/TOTAL <<"%" << endl;
			start = clock();
			writeTEMP();
			printSeq(_sequence, _v, "tmp");
		}
		if (isTP(_sequence, _v))
		{
			writeSeq2File();
			printSeq(_sequence, _v, "FIND! ");
			isFound = true;
			break;
		}
		else {
			nextPermute(_sequence, _v);
		}
	}
	if (!isFound) 
	{
		writeSeq2File("THERE ARE NO");
	}
}
Пример #2
0
void Seeker::seekConvertions()
{
	unsigned long long int st, fi, i;
	std::string::size_type sz = 0;

	st = stoull(_initNum, &sz, 0);
	st = st == 0 ? 0 : st;
	fi = stoull(_finishNum, &sz, 0);
	fi = fi == 0 ? ipow(_base, _v) : fi;
	unsigned long long int TOTAL = fi - st;
	cout << "Begin looking in diapasone: " << st << " to " << fi << endl;
	double duration, start = clock();

	for (i = st; i < fi; i++)
	{
		duration = (clock() - start) / (double)CLOCKS_PER_SEC;
		convertNum2Seq(_sequence, i, _base, _v);
		if (duration > SHOW_TIME)
		{
			cout << "Done: " << (i-st)*100./TOTAL << "%" << endl;
			start = clock();
			writeTEMPNum(i);
			printSeq(_sequence, _v, "tmp");
		}
		if (isSuiteToBrookRaiserChovla(_sequence, _v))
		{
			if (isTP(_sequence, _v))
			{
				writeSeq2File();
				printSeq(_sequence, _v, "GOOD!");
			}
		}
	}
}
Пример #3
0
struct dhlist * DHFlush(struct dhlist * DHliste, const int pos) {
/*****************************************************************************
 * Grand Flusher alt i denne liste.
 *****************************************************************************/
  long dis;

  if (DHliste->post)
    DHliste->post = DHFlush(DHliste->post, pos);

  dis = DHliste->stop1 - DHliste->start1 + 1; 
  if (DHliste->stop2 + gap + klgde < pos) {
    /*
      dprintf("Flush  dhliste(%10p) pre:%10p post:%10p\n", 
      DHliste, DHliste->pre, DHliste->post);
	    
      dprintf("Q %d <%ld, %ld> > %d\n", 
      pos, DHliste->start2, DHliste->stop2, DHliste->Ins);
    */
    if (dis > min) {
      //      dprintf("F %p <%ld, %ld> > %ld\n", 
      //      DHliste, DHliste->start2, DHliste->stop2, dis);
      if ((!max) || (max > dis))
	printSeq(DHliste->start1, DHliste->stop1, 
		 DHliste->start2, DHliste->stop2,
		 DHliste->Ins);
    }
    return (DeleteDHNode(DHliste));    
  }
  //  dprintf("S %d <%ld, %ld> > %ld\n", pos, DHliste->start2, DHliste->stop2, dis);
  return (DHliste);    
}
Пример #4
0
int main() {

  std::vector<int> demoVec;
  std::list<int> demoLst;

  // First we put something in our vector and our list..
  for(int i=1; i<10; i++) {
    demoVec.push_back(i);
    demoLst.push_back(i);
  }

  // Now call our printSeq function (note we don't need to specify the template  parameter in this case..
  printSeq("vec: ", demoVec.begin(), demoVec.end());
  printSeq("lst: ", demoLst.begin(), demoLst.end());

  // While we are not required to specify the template parameter, we can.  If we did, it would look something like this:
  // printSeq<std::vector<int>::iterator >("vec: ", demoVec.begin(), demoVec.end());
  // printSeq<std::list<int>::iterator   >("lst: ", demoLst.begin(), demoLst.end());
} /* end func main */
Пример #5
0
std::ostream&
operator<<(std::ostream& os, const AssembledContig& contig)
{
    os << "CONTIG size: " << contig.seq.size()
       << " seedCount: " << contig.seedReadCount
       << " supportReads: " << contig.supportReads.size()
       << " seq:\n";
    printSeq(contig.seq,os);
    os << "\n";

    return os;
}
Пример #6
0
struct dhlist * DHLastFlush(struct dhlist * DHliste) {
/*****************************************************************************
 * Flusher alt i denne liste.
 *****************************************************************************/
  long dis;

  if (DHliste->post)
    DHliste->post = DHLastFlush(DHliste->post);

  dis = DHliste->stop1 - DHliste->start1 + 1; 

  if (dis > min) {
    if ((!max) || (max > dis))
      printSeq(DHliste->start1, DHliste->stop1, 
	       DHliste->start2, DHliste->stop2,
	       DHliste->Ins);
  }
  return (DeleteDHNode(DHliste));    
}
Пример #7
0
void remember()
{
	int numberList[] = {682, 220, 82, 220, 79, 298, 79, 144, 82, 69, 157, 69, 229, 288};
	const int length = 14;
	printSeq(numberList, length);
}
Пример #8
0
void turnOff()
{
	int numberList[] = {682, 220, 82, 220, 79, 72, 305, 69, 82, 220, 79, 147, 79, 364};
	const int length = 14;
	printSeq(numberList, length);
}
Пример #9
0
void turnOn()
{
	int numberList[] = {682, 220, 82, 220, 79, 295, 82, 144, 82, 69, 229, 514};
	const int length = 12;
	printSeq(numberList, length);
}
Пример #10
0
void dimDown()
{
	int numberList[] = {682, 223, 79, 220, 82, 370, 79, 295, 82, 69, 82, 439};
	const int length = 12;
	printSeq(numberList, length);
}
Пример #11
0
void dimUp()
{
	int numberList[] = {682, 220, 82, 220, 82, 370, 79, 220, 82, 220, 79, 367};
	const int length = 12;
	printSeq(numberList, length);
}
Пример #12
0
static UBool testConvertFromUnicode(const UChar *source, int sourceLen,  const uint8_t *expect, int expectLen, 
                const char *codepage, UBool fallback, const int32_t *expectOffsets)
{


    UErrorCode status = U_ZERO_ERROR;
    UConverter *conv = 0;
    char junkout[NEW_MAX_BUFFER]; /* FIX */
    int32_t junokout[NEW_MAX_BUFFER]; /* FIX */
    const UChar *src;
    char *end;
    char *targ;
    int32_t *offs;
    int i;
    int32_t   realBufferSize;
    char *realBufferEnd;
    const UChar *realSourceEnd;
    const UChar *sourceLimit;
    UBool checkOffsets = TRUE;
    UBool doFlush;
    UBool action=FALSE;
    char *p;


    for(i=0;i<NEW_MAX_BUFFER;i++)
        junkout[i] = (char)0xF0;
    for(i=0;i<NEW_MAX_BUFFER;i++)
        junokout[i] = 0xFF;
    setNuConvTestName(codepage, "FROM");

    log_verbose("\nTesting========= %s  FROM \n  inputbuffer= %d   outputbuffer= %d\n", codepage, gInBufferSize, 
            gOutBufferSize);

    conv = my_ucnv_open(codepage, &status);
    if(U_FAILURE(status))
    {
        log_data_err("Couldn't open converter %s\n",codepage);
        return TRUE;
    }

    log_verbose("Converter opened..\n");
    /*----setting the callback routine----*/
    ucnv_setFallback (conv, fallback);
    action = ucnv_usesFallback(conv);
    if(action != fallback){
        log_err("FAIL: Error is setting fallback. Errocode=%s\n", myErrorName(status));
    }
    /*------------------------*/
    src = source;
    targ = junkout;
    offs = junokout;

    realBufferSize = (sizeof(junkout)/sizeof(junkout[0]));
    realBufferEnd = junkout + realBufferSize;
    realSourceEnd = source + sourceLen;

    if ( gOutBufferSize != realBufferSize )
        checkOffsets = FALSE;

    if( gInBufferSize != NEW_MAX_BUFFER )
        checkOffsets = FALSE;

    do
    {
        end = nct_min(targ + gOutBufferSize, realBufferEnd);
        sourceLimit = nct_min(src + gInBufferSize, realSourceEnd);

        doFlush = (UBool)(sourceLimit == realSourceEnd);

        if(targ == realBufferEnd)
        {
            log_err("Error, overflowed the real buffer while about to call fromUnicode! targ=%08lx %s", targ, gNuConvTestName);
            return FALSE;
        }
        log_verbose("calling fromUnicode @ SOURCE:%08lx to %08lx  TARGET: %08lx to %08lx, flush=%s\n", src,sourceLimit, targ,end, doFlush?"TRUE":"FALSE");


        status = U_ZERO_ERROR;

        ucnv_fromUnicode (conv,
                  (char **)&targ,
                  (const char *)end,
                  &src,
                  sourceLimit,
                  checkOffsets ? offs : NULL,
                  doFlush, /* flush if we're at the end of the input data */
                  &status);

    } while ( (status == U_BUFFER_OVERFLOW_ERROR) || (sourceLimit < realSourceEnd) );

    if(U_FAILURE(status))
    {
        log_err("Problem doing toUnicode, errcode %d %s\n", myErrorName(status), gNuConvTestName);
        return FALSE;
    }

    log_verbose("\nConversion done [%d uchars in -> %d chars out]. \nResult :",
        sourceLen, targ-junkout);
    if(VERBOSITY)
    {
        char junk[9999];
        char offset_str[9999];

        junk[0] = 0;
        offset_str[0] = 0;
        for(p = junkout;p<targ;p++)
        {
            sprintf(junk + uprv_strlen(junk), "0x%02x, ", (0xFF) & (unsigned int)*p);
            sprintf(offset_str + strlen(offset_str), "0x%02x, ", (0xFF) & (unsigned int)junokout[p-junkout]);
        }

        log_verbose(junk);
        printSeq((const unsigned char*)expect, expectLen);
        if ( checkOffsets )
        {
            log_verbose("\nOffsets:");
            log_verbose(offset_str);
        }
        log_verbose("\n");
    }
    ucnv_close(conv);


    if(expectLen != targ-junkout)
    {
        log_err("Expected %d chars out, got %d %s\n", expectLen, targ-junkout, gNuConvTestName);
        log_verbose("Expected %d chars out, got %d %s\n", expectLen, targ-junkout, gNuConvTestName);
        printSeqErr((const unsigned char*)junkout, (int32_t)(targ-junkout));
        printSeqErr((const unsigned char*)expect, expectLen);
        return FALSE;
    }

    if (checkOffsets && (expectOffsets != 0) )
    {
        log_verbose("\ncomparing %d offsets..\n", targ-junkout);
        if(uprv_memcmp(junokout,expectOffsets,(targ-junkout) * sizeof(int32_t) )){
            log_err("\ndid not get the expected offsets while %s \n", gNuConvTestName);
            log_err("Got  : ");
            printSeqErr((const unsigned char*)junkout, (int32_t)(targ-junkout));
            for(p=junkout;p<targ;p++)
                log_err("%d, ", junokout[p-junkout]); 
            log_err("\nExpected: ");
            for(i=0; i<(targ-junkout); i++)
                log_err("%d,", expectOffsets[i]);
        }
    }

    log_verbose("\n\ncomparing..\n");
    if(!memcmp(junkout, expect, expectLen))
    {
        log_verbose("Matches!\n");
        return TRUE;
    }
    else
    {
        log_err("String does not match. %s\n", gNuConvTestName);
        log_verbose("String does not match. %s\n", gNuConvTestName);
        printSeqErr((const unsigned char*)junkout, expectLen);
        printSeqErr((const unsigned char*)expect, expectLen);
        return FALSE;
    }
}
Пример #13
0
struct dhlist * CalcFragRepGar(struct dhlist * dhliste, 
			       const int start1, 
			       const int start2,
			       const int ins) {
/******************************************************************************
 * Løber en dhliste igennem, og undersøger om det er del af en struktur, ellers
 * oprettes der en ny node som værdierne gemmes i.
 *****************************************************************************/
  int dist;
  // Guldet i systemet ....!!!!.... .

  // If there dont exists a list one is created
  if (!dhliste) {
    // Since this is a insertion it shouldn't be created after all
    if (ins != 0)
      return NULL;

    dhliste = MakeDHList();
    dhliste->start1 =  start1;
    dhliste->start2 =  start2;
    dhliste->stop1  = start1 + klgde - 1;
    dhliste->stop2  = start2 + klgde - 1;
    dhliste->fragNum    =  0;  

    // Since this element was just created there is no reason in checking 
    // for other elements in the same distance
    return(dhliste);
  }

  dprintf("info dhliste(%10p) pre:%10p post:%10p\n", 
	 dhliste, dhliste->pre, dhliste->post);

  if ((dhliste->start1 < start1) && 
      (dhliste->stop1 + gap + klgde >= start1) && 
      (dhliste->start2 <= start2) &&
      (dhliste->stop2 + gap + klgde >= start2)) {

    if (ins)
      dhliste->Ins = 1;

    dhliste->stop1 = start1 + klgde - 1;
    dhliste->stop2 = start2 + klgde - 1;
    dhliste->fragNum = dhliste->fragNum + 1;

    dprintf("  dhliste(%10p) start1:%10ld start2:%10ld\n", 
    	    dhliste, dhliste->start1, dhliste->start2);

  }
  else if (dhliste->post){
    //    dprintf("recursiv\n");
    dhliste->post = CalcFragRepGar(dhliste->post, start1, start2, ins);
  }
  else {
    // No one matches, we create a new one
    dhliste = addDHNode(dhliste);
    dhliste->start1 =  start1;
    dhliste->start2 =  start2;
    dhliste->stop1  = start1 + klgde - 1;
    dhliste->stop2  = start2 + klgde - 1;

    //Da denn post lige er oprettet er der ingen grund til at checke
    return(dhliste);
  }

  // Skal vi slette et par poster dhlister sammen ????
  // Hvis Mem >= 2 printer vi også de poster der ikke kan gro mere....

  dist = dhliste->stop1 - dhliste->start1 + 1; 
  if (((dist < min) &&
       (dhliste->stop2 + gap + klgde <= start2)) ||
      ((dist >= min) && (dhliste->stop2 + gap + klgde <= start2))){

    //    dprintf("del  dhliste(%10p) pre:%10p post:%10p\n", 
    //	    dhliste, dhliste->pre, dhliste->post);

    if ((dist >= min) && 
	(dhliste->stop2 + gap + klgde <= start2)) {

      //      printf("Q %p <%ld, %ld> > %ld\n", 
      //	     dhliste, dhliste->start1, dhliste->stop1, dist);

      if ((!max) || (max > dist))
	printSeq(dhliste->start1, dhliste->stop1, 
		 dhliste->start2, dhliste->stop2,
		 dhliste->Ins);
    }
    return (DeleteDHNode(dhliste));
  }

  return(dhliste);
}
Пример #14
0
int main(void) {

	setvbuf(stdout, NULL, _IONBF, 0);

	Header head;

	head.head = NULL;
	head.tail = NULL;
	head.nodeCount = 0;

	int menu = 0, list = 0;

	do {

		do {
			system("cls");
			printf("\n Manipular qual lista.\n");
			printf("1 - Encadeada.\n");
			printf("2 - Sequencial.\n");

			scanf("%d", &list);

			system("cls");
		} while (list != 1 && list != 2);

		system("cls");
		printf("\n Digite o numero da opcao desejada.\n");
		printf("1 - Inserir elemento no final da lista.\n");
		printf("2 - Inserir elemento no inicio da lista.\n");
		printf("3 - Remover elemento a partir de um valor.\n");
		printf("4 - Imprimir a lista.\n");
		printf("5 - Inserir na posicao N.\n");
		printf("6 - Remover ultimo da lista.\n");
		printf("7 - Remover primeiro da lista.\n");
		printf("8 - Remover elemento na posicao N.\n");
		printf("9 - Carregar lista do arquivo.\n");
		printf("10 - Salvar lista atual em arquivo.\n");
		printf("11 - Inserction.\n");
		printf("12 - Selection.\n");
		printf("13 - Bubble.\n");
		printf("14 - Shell.\n");
		printf("15 - Quick.\n");
		printf("16 - Merge.\n");
		printf("17 - Busca Binaria.\n");
		printf("18 - Busca Seq.\n");

		printf("20 - Sair.\n");

		scanf("%d", &menu);

		system("cls");

		switch (menu) {
		case 1:
			if (list == 1) {
				insertNodeAtTheEnd(&head, getValue(), 1);
				reference(&head);
			} else {
				insertSeqAtTheEnd(getValue(), 1);
			}
			break;
		case 2:
			if (list == 1) {
				insertNodeAtStart(&head, getValue(), 1);
				reference(&head);
			} else {
				insertSeqAtStart(getValue(), 1);
			}
			break;
		case 3:
			if (list == 1) {
				deleteNodeByValue(&head);
				reference(&head);
			} else {
				deleteSeqByValue();
			}
			break;
		case 4:
			if (list == 1) {
				printList(&head);
			} else {
				printSeq();
			}
			break;
		case 5:
			if (list == 1) {
				insertAtN(&head, getValue(), getPosIns(&head));
				reference(&head);
			} else {
				insertSeqAtN(getValue(), getPosSeqIns());
			}
			break;
		case 6:
			if (list == 1) {
				deleteLastNode(&head, 1);
				reference(&head);
			} else {
				deleteLastSeq(1);
			}
			break;
		case 7:
			if (list == 1) {
				deleteFirstNode(&head, 1);
				reference(&head);
			} else {
				deleteFirstSeq(1);
			}
			break;
		case 8:
			if (list == 1) {
				deleteNodeAtN(&head, getPosDel(&head));
				reference(&head);
			} else {
				deleteSeqAtN(getPosSeqDel(), 1);
			}
			break;
		case 9:
			listOptions(&head, list);
			break;
		case 10:
			if (list == 1) {
				writeLinkedList(&head);
			} else {
				writeSequentialList();
			}
			break;
		case 11:
			if (list == 1) {
				linkedInserctionSort(&head);
			} else {
				inserctionSort();
			}
			break;
		case 12:
			if (list == 1) {
				linkedSelectionSort(&head);
			} else {
				selectionSort();
			}
			;
			break;
		case 13:
			if (list == 1) {
				linkedBubbleSort(&head);
			} else {
				bubbleSort();
			}
			break;
		case 14:
			if (list == 1) {
				linkedShellSort(&head);
			} else {
				shellSort();
			}
			break;
		case 15:
			if (list == 1) {
				linkedCallQuickSort(&head);
			} else {
				callQuickSort();
			}
			break;
		case 16:
			if (list == 1) {
				linkedCallMergeSort(head.nodeCount);
			} else {
				callMergeSort();
			}
			break;
		case 17:
			if (list == 1) {
				linkedCallBynarySearch(&head);
			} else {
				callBynarySearch();
			}
			break;
		case 18:
			if (list == 1) {
				searchNodeByValue(&head);
			} else {
				searchByValue();
			}
			break;
		}

	} while (menu != 20);

	wipeList(&head);

	return EXIT_SUCCESS;
}