예제 #1
0
static void initGeneratorStatistics(GeneratorStatistics *gen)
{
   int i;

   if( initSequence(&gen->transactionSequence,
                    transactionDefinition) != 0 ) {
      ndbout_c("could not set the transaction types");
      exit(0);
   }

   if( initSequence(&gen->rollbackSequenceT4,
                    rollbackDefinition) != 0 ) {
      ndbout_c("could not set the rollback sequence");
      exit(0);
   }

   if( initSequence(&gen->rollbackSequenceT5,
                    rollbackDefinition) != 0 ) {
      ndbout_c("could not set the rollback sequence");
      exit(0);
   }

   for(i = 0; i < NUM_TRANSACTION_TYPES; i++ )
      clearTransaction(&gen->transactions[i]);

   gen->totalTransactions = 0;

   gen->activeSessions.numberInList = 0;
   gen->activeSessions.readIndex    = 0;
   gen->activeSessions.writeIndex   = 0;
}
예제 #2
0
int main() {
    char* strMid = "9+(3-1)*3+10/2+1000*10";
    Sequence mid;
    initSequence(&mid);
    initMid(&mid, strMid);
    printExpression(&mid);

    Sequence post;
    initSequence(&post);
    initPost(&mid, &post);
    printExpression(&post);

    printf("Result=%d\n", calculate(&post));
    return 0;
}
예제 #3
0
/***********************************************************************
 * Create array of indexes from S which omit all except the last 
 * repeated value.
***********************************************************************/
sequence removeRuns(const u8 *S, const size_t size){
  sequence toReturn = initSequence(size);
  toReturn.size = 0;
  for(size_t i = 0; i < size; i++) //if(S[i] != S[i+1])
    toReturn.S[toReturn.size++] = i;
  toReturn.S = realloc(toReturn.S, toReturn.size * sizeof(*toReturn.S));
  return toReturn;
}
예제 #4
0
/***********************************************************************
 * original BPR2
***********************************************************************/
sequence bpr2direct(const u8 *source, const size_t length){

  sequence toReturn = initSequence(length);
  
  for(size_t i = 0; i < length; i++) toReturn.S[i] = i;
  
  recursiveBucketSort(toReturn.S, toReturn.size, source, length, 0);
  
  return toReturn;
}
예제 #5
0
/***********************************************************************
 * tweaked BPR2 to handle some changes nessicary for run removal
***********************************************************************/
sequence bpr2dereferenced(const u8 *source, const size_t length, const sequence input){

  sequence toReturn = initSequence(input.size);
  
  memcpy(toReturn.S, input.S, toReturn.size * sizeof(*toReturn.S));
  
  recursiveBucketSort(toReturn.S, toReturn.size, source, length, 0);
  
  return toReturn;
}
예제 #6
0
/***********************************************************************
 * Re-add runs of elements into SSA
 * 
 * proxy: the SSA arranged repeats removed indexes
 * 
***********************************************************************/
sequence addRuns(const u8 *input, const size_t length, sequence proxy){

//DECLARATIONS//////////////////////////////////////////////////////////
  sequence toReturn;
  //size_t numToExpand;
  
//INITIALIZATIONS///////////////////////////////////////////////////////
  toReturn = initSequence(length);
  memcpy(toReturn.S, proxy.S, sizeof(*toReturn.S) * toReturn.size);
  //toReturn.size = 0;
  
//OPERATIONS////////////////////////////////////////////////////////////
  /*for(size_t i = 1; i < proxy.size; i++){
    const char isARepeat = input[proxy.S[i]] == input[proxy.S[i]-1];
    if(!isARepeat){
      toReturn.S[toReturn.size++] = proxy.S[i];
    }else{
      //size_t j = i+1;
      while(proxy.S[i] - numToExpand > 0 && 
            input[proxy.S[i] - (numToExpand+1)] == 
                                        input[proxy.S[i] - numToExpand])
        numToExpand++;

      size_t *foundToRepeat;
      //Here we flatten the 2D array and will just use a more complex
      //accessing portion in order to avoid more calls to malloc.
      foundToRepeat = malloc(sizeof(*foundToRepeat) * numToExpand * 3);
      //NOTE: in parsing as entries become exausted, the pointers for
      //reading and writing should be seperate so that in the course of 
      //each expantion iteration old entries are removed in an efficient
      //manner.
      
      //populate the entries to expand
      if(proxy.S[i]+1 < length || input[proxy.S[i]] < input[proxy.S[i]+1]){//left expansion
        for(size_t k = numToExpand-1; k != ((size_t)0)-1; k--){
          toReturn.S[toReturn.size++] = proxy.S[i] - k;
        }
      }else{//right expansion
        for(size_t k = 0; k < numToExpand; k++){
          toReturn.S[toReturn.size++] = proxy.S[i] - k;
        }
      }
      
    }
  }*/

//CLEAN UP//////////////////////////////////////////////////////////////


  return toReturn;
}
예제 #7
0
	void Player::initPlayer(ClipEntry& clipEntry)
    {
		this->clipEntry = &clipEntry;
        clipMaskFileNames = ReadLines(Config.GetForegroundFolder(clipEntry));

		frameNumber = clipEntry.GetFrameCount();
		cout << "frameNumber: " << frameNumber << endl;
		startFrameNumber = 0;
		nowFrameNumber = 0;
		waitKeyNumber = 32;
		nowSequenceNumber = 0;

		weightPath = Config.GetWeightsPath(clipEntry);
		weightW = 1000;
		weightH = 200;

		sequencePath = Config.GetSequencePath(clipEntry);
		initWeight();
		initSequence();

		namedWindow("Display", CV_WINDOW_AUTOSIZE);
		namedWindow("Foreground", CV_WINDOW_AUTOSIZE);
		namedWindow("Weight", CV_WINDOW_AUTOSIZE);
		createTrackbar("Frame", "Weight", 0, frameNumber-1, changeBar, (void*)this);
		setTrackbarPos("Frame", "Weight", nowFrameNumber);
		createTrackbar("Speed", "Weight", 0, 6, changeSpeed, (void*)this);
		setTrackbarPos("Speed", "Weight", 3);

		
		if(clipEntry.Type == ClipType::Video){
			Mat frame;
			int num = 11;

			while(num--)
				clipEntry.Video.read(frame);
		}
		

		showFrame(s[0],1);

		loop();
		
	}
예제 #8
0
void
consensus (void *space, Uint *consensus, Uint len, IntSequence *query,
		Uint seedlen, void* info) {

    Uint i,j;	
	char *constr;	
	double sum, norm;
	double *consensus_double;
	double *seedprobability;
	
	imbissinfo *imbiss;	
	IntSequence *consensusSequence;
	gnuplot_ctrl *h;

	imbiss = (imbissinfo*) info;
    

	seedprobability = ALLOCMEMORY(space, NULL, double, len);
	for (i=0; i < len; i++) {
		for (sum=0.0, j=0; j < seedlen; j++) {
			sum += imbiss->score[(Uint) query->sequence[i+j]];
		}
		seedprobability[i] = log10(imbiss->K*2500000*seedlen*
			exp(-(double)imbiss->lambda*sum));
	}
	
	consensusSequence = initSequence(space);
	consensusSequence->sequence = consensus;
	consensusSequence->length = len;
	
	constr = printSequence(space, consensusSequence, 60);
	printf("%s\n", constr);
	FREEMEMORY(space, constr);
	
    consensus_double = ALLOCMEMORY(space, NULL, double, len);
	
	h = gnuplot_init();
	gnuplot_setstyle(h, "lines");
	sum = 0;
	for(i=0; i < len; i++) {
		sum += consensus[i];
	}
	
	for(i=0; i < len; i++) {
	  norm = consensus[i];
	  norm = (norm > 0) ? norm : 1;
	  consensus_double[i] = log10(norm);
	
		/*	log10(imbiss->K*3000000*len*exp(-(double)consensus[i]));
		  if (consensus_double[i] < -400) consensus_double[i]=-400;*/
	}

	gnuplot_cmd(h, "set title 'IMBISS - seed statistics' -28,0 font'Helvetica,15'");	
	gnuplot_cmd(h, "set label '%s' at screen 0.12,0.92 font 'Helvetica,12'", imbiss->query->strings[0].str);
	gnuplot_cmd(h, "set label 'seed length: %d' at graph 0.05,0.95 font 'Helvetica, 12'", seedlen);
	gnuplot_set_xlabel(h, "query sequence residue");
	gnuplot_set_ylabel(h, "log");	
	gnuplot_plot_x(h, consensus_double, len, "log(number of matches)");
	gnuplot_plot_x(h, seedprobability, len,  "log(Kmn*e^{lambda*score(seed)})");
	
	FREEMEMORY(space, seedprobability);
	FREEMEMORY(space, consensus_double);
	FREEMEMORY(space, consensusSequence);
}
예제 #9
0
void stick1trig(void) { 
   seqstate = 1;           // enable playing of sequence
   nextnotetime = t_time;
   initSequence(x, xx, alpha, beta, baton.x1t, baton.y1t);
   nextHenon(alpha, beta, x, xx); // ignore first value
}
예제 #10
0
/***********************************************************************
* Suffix Array Induced Sorting (SAIS) is a linear time/space suffix 
* array construction algorithm which competes with BPR2 for top 
* time/space requirements.  TODO: reference paper here.
* 
* Currently this code is being changes to enable testing of run-removal
* on the code.  Run removal enforces stricter conditions on the input 
* sequence which allows for some of the logic to be simplified.  This
* experimental approach is particularly useful for inputs with small
* alphabets in the general case, but definitionally saves on sequences 
* which are known to have many runs of identical values in the sequence.
* 
* @source  :The sequence to construct the suffix array on.
* @runsRem :
* 
* @alphabetSize : not actually alphabet size, but highest value seen in 
*                 alphabet.  Might change in future.
* 
* 
* Notes
* 0 = undefined, 1 = L, 2 = S, 3 = {LMS, M}
***********************************************************************/
sequence SAIS(const u8 *source, const size_t sourceLength, 
                        const sequence runsRem, const u8 alphabetSize){
//DECLARATIONS//////////////////////////////////////////////////////////
  sequence toReturn, sanityCheck;
  size_t **bucket;
  size_t **oldBucket;
  size_t i;
  size_t *bucketSize;
  size_t *bucketFrontCounter;
  size_t *bucketEndCounter;
  
  unsigned char *LMSandLS;

////INITIALIZATION//////////////////////////////////////////////////////
  LMSandLS  = malloc(sizeof(unsigned char) * runsRem.size);
  bucket    = malloc(sizeof(*bucket) * alphabetSize);
  oldBucket = malloc(sizeof(*oldBucket) * alphabetSize);
  bucketSize = calloc(sizeof(size_t)* alphabetSize, 1);
  bucketFrontCounter = calloc(sizeof(size_t)* alphabetSize, 1);
  bucketEndCounter = calloc(sizeof(size_t)* alphabetSize, 1);
  sanityCheck = initSequence(runsRem.size);
  memset(sanityCheck.S, 0, sizeof(*sanityCheck.S) * sanityCheck.size);
  sanityCheck.size = 0;

  /*prescan for buckets************************************************/
  //calculate bucket sizes
  
  for(i = 0; i < runsRem.size; i++) bucketSize[source[runsRem.S[i]]]++;

  //calculate bucket start and stops
  for(short i = 0; i < alphabetSize; i++){
    bucket[i] = calloc(sizeof(size_t), bucketSize[i]);
    oldBucket[i] = calloc(sizeof(size_t), bucketSize[i]);
  }

#ifdef DEBUG
  //first place where bucket data can be printed
  fprintf(stderr, "%lu\n", runsRem.size);
  printBucket(bucket, alphabetSize, bucketSize);
#endif


//OPERATION/////////////////////////////////////////////////////////////
  /*set up L, S, and LMS metadata**************************************/
  /*The paper stipulates an additional universally minimal character
   * which is definitionally LMS, but here it is simulated.*/

  //Assign characters' values right to left (end to beginning) for L, S,
  //and LMS
  size_t loopUntil = runsRem.size - 2;
  LMSandLS[runsRem.size-1] = _L_;
  for(i = loopUntil; i != ((size_t)0)-1; i--)
    LMSandLS[i] = source[runsRem.S[i]] > source[runsRem.S[i+1]] ? _L_ : _S_;
  
  i=0;
  while(1){
    while(i < loopUntil && LMSandLS[i] == _L_) i++;
    if(i >= loopUntil) break;
    LMSandLS[i++] = _LMS_;
    while(i < loopUntil && LMSandLS[i] == _S_) i++;
    if(i >= loopUntil) break;
  }

#ifdef DEBUG
  printLMSandLS(LMSandLS, runsRem.size);

  fprintf(stderr, "\n\nAdding to buckets\n\n");
#endif

/*PRIMEER***************************************Add entries to buckets*/
  //This is supposed to prepare the data to be induce sorted.

  memcpy(bucketEndCounter, bucketSize, sizeof(*bucketEndCounter) * alphabetSize);
  
  bucket[source[runsRem.S[runsRem.size-1]]][0] = runsRem.size-1;
  //bucketFrontCounter[bucketLocation]++;
  
  //LMS type right-to-left scan -- Add LMS entries to the ends of
  //various buckets going from right to left.  The result is partially
  //full buckets with LMS entries in acending order.
  for(size_t i = runsRem.size-1; i != ((size_t)0)-1; i--){
    if(LMSandLS[i] == _LMS_){
      const unsigned char target = source[runsRem.S[i]];
      bucket[target][--bucketEndCounter[target]] = i;
    }
  }
  

/*LOOP OVER UNTIL COMPLETE*********************************************/
//TODO: there's some really ugly ways to make this run faster.
  //L type left-to-right scan, not exactly a direct reasoning for this,
  //please refer to the paper.  Bounds checking was used in place of
  //checking for negative values so that -1 didn't have to be used,
  //allowing architentually maximal string length.
  char goOn;
  do{
    goOn = 0;
    memset(sanityCheck.S, 0, sizeof(*sanityCheck.S) * runsRem.size);
    sanityCheck.size = 0;

    //step 3 of setting up SA
    //L type right to left scan.
    memcpy(bucketEndCounter, bucketSize, sizeof(*bucketEndCounter) * alphabetSize);
    for(i = alphabetSize-1; i != ((size_t)0)-1 ; i--){
      for(size_t j = bucketSize[i]-1; j != ((size_t)0)-1; j--){
        if(!bucket[i][j]) continue;
        const size_t target = bucket[i][j]-1;

        if(LMSandLS[target] == _L_ || LMSandLS[target] == _LMS_){
          char KILLYOSELF = 0;
          if(source[runsRem.S[target]] == source[runsRem.S[runsRem.size-1]] && bucketEndCounter[source[runsRem.S[target]]]-1 == 0){
            KILLYOSELF = 1;
            printf("Trying to write over something you're blatently not supposed to write over.\n");
          }
          for(size_t k = 0; k < sanityCheck.size; k++)
            if(sanityCheck.S[k] == target){
              KILLYOSELF=1;
              printf("trying to write a %lu a second time.\n", target);
            }
          
          if(KILLYOSELF){
            printf("KILL YO SELF in r to l\n");
            exit(1);
          }
          const unsigned char target2 = source[runsRem.S[target]];
          bucket[target2][--bucketEndCounter[target2]] = target;
          sanityCheck.S[sanityCheck.size++] = target;
        }
      }
    }

#ifdef DEBUG
    printBucket(bucket, alphabetSize, bucketSize);
#endif
    
    //S type left to right scan.
    memset(bucketFrontCounter, 0, sizeof(*bucketFrontCounter) * alphabetSize);
    //bucket[source[runsRem.S[runsRem.size-1]]][0] = runsRem.size-1;
    bucketFrontCounter[source[runsRem.S[runsRem.size-1]]] = 1;//protect last index
  
    for(int i = 0; i < alphabetSize; i++){
      for(size_t j = 0; j < bucketSize[i]; j++){
        if(!bucket[i][j]) continue;
        const size_t target = bucket[i][j]-1;
        
        if(LMSandLS[target] == _S_){
          char KILLYOSELF = 0;
          if(source[runsRem.S[target]] == source[runsRem.S[runsRem.size-1]] && bucketEndCounter[source[runsRem.S[target]]]-1 == 0){
            KILLYOSELF = 1;
            printf("Trying to write over something you're blatently not supposed to write over.\n");
          }
          for(size_t k = 0; k < sanityCheck.size; k++)
            if(sanityCheck.S[k] == target){
              KILLYOSELF=1;
              printf("trying to write a %lu a second time.\n", target);
            }
          
          if(KILLYOSELF){
            printf("KILL YO SELF in l to r\n");
            exit(1);
          }
          const unsigned char target2 = source[runsRem.S[target]];
          bucket[target2][bucketFrontCounter[target2]++] = target;
          sanityCheck.S[sanityCheck.size++] = target;
        }
      }
    }

    for(i = 0; i < alphabetSize; i ++)
      if(memcmp(bucket[i], oldBucket[i], bucketSize[i] * sizeof(size_t))){
        for(size_t j = i; j < alphabetSize; j++)
          if(bucketSize[j])
            memcpy(oldBucket[j], bucket[j], sizeof(*bucket) * bucketSize[j]);
        goOn = 1;
        break;
      }

  }while(goOn);

#ifdef DEBUG
    printBucket(bucket, alphabetSize, bucketSize);
#endif

//CLEAN UP//////////////////////////////////////////////////////////////

  free(LMSandLS);
  
  toReturn = initSequence(runsRem.size);
  toReturn.size = 0;
  for(i = 0; i < alphabetSize; i++)
    for(size_t j = 0; j < bucketSize[i]; j++)
      toReturn.S[toReturn.size++] = bucket[i][j];
  return toReturn;
}