Example #1
0
void process2(trip a[MAXN], int*ac, char s[MAXN], int sc, int*pos){
  if      (s[*pos  ] == '['){
    while (s[*pos] != ']') {
      (*pos)++;
      int num = 0;
      while ((s[*pos] != ',') && (s[*pos] != ']')) {
        num = num * 10 + (int)(s[*pos] - '0');
        (*pos)++;
      }
      a[*ac].first = num;
      a[*ac].second.first = -1;
      a[*ac].second.second = -1;
      (*ac)++;
    }
    (*pos)++;
  }
  else if (s[*pos  ] == 'c'){
    (*pos) += 7;
    process2(a, ac, s, sc, pos);
    (*pos)++;
    process2(a, ac, s, sc, pos);
    (*pos)++;
  }
  else if (s[*pos+1] == 'o'){
    (*pos) += 7;
    process2(a, ac, s, sc, pos);
    (*pos)++;
  }
  else {
    (*pos) += 8;
    process2(a, ac, s, sc, pos);
    (*pos)++;
  }
}
Example #2
0
int main()
{
    const char buf[] = "i am children 2";

    nokia::AffinityProcess process1(Process1);
    nokia::AffinityProcess process2(Process2, static_cast<void*>(const_cast<char*>(buf)));
    nokia::AffinityProcess process3(Process2, static_cast<void*>(const_cast<char*>("22")));
    nokia::AffinityProcess process4(Process2, static_cast<void*>(const_cast<char*>("33")));
    nokia::AffinityProcess process5(Process2, static_cast<void*>(const_cast<char*>("44")));
    nokia::AffinityProcess process6(Process2, static_cast<void*>(const_cast<char*>("55")));
    nokia::AffinityProcess process7(Process2, static_cast<void*>(const_cast<char*>("66")));
    nokia::AffinityProcess process8(Process2, static_cast<void*>(const_cast<char*>("77")));
    nokia::AffinityProcess process9(Process2, static_cast<void*>(const_cast<char*>("88")));
    nokia::AffinityProcess process10(Process2, static_cast<void*>(const_cast<char*>("99")));

    process1.Wait();
    process2.Wait();
    process3.Wait();
    process4.Wait();
    process5.Wait();
    process6.Wait();
    process7.Wait();
    process8.Wait();
    process9.Wait();
    process10.Wait();
    return 0;
}
Example #3
0
void process (trip a[MAXN], int*ac, char s[MAXN], int sc, int*pos){
  if      (s[*pos  ] == '['){
    while (s[*pos] != ']'){
      (*pos)++;
      int num = 0;
      while ((s[*pos] != ',') && (s[*pos] != ']')) {
        num = num * 10 + (int)(s[*pos] - '0');
        (*pos)++;
      }
      a[*ac].first = num;
      a[*ac].second.first = -1;
      a[*ac].second.second = -1;
      (*ac)++;
    }
    (*pos)++;
  }
  else if (s[*pos  ] == 'c'){
    (*pos) += 7;
    process(a, ac, s, sc, pos);
    (*pos)++;
    process(a, ac, s, sc, pos);
    (*pos)++;
  }
  else if (s[*pos+1] == 'o'){
    (*pos) += 7;
    int cur = *ac;
    process2(a, ac, s, sc, pos);
    qsort(a+cur, (*ac)-cur, sizeof(trip), cmpT);
    (*pos)++;
  }
  else {
    (*pos) += 8;
    int cur = *ac;
    process2(a, ac, s, sc, pos);
    qsort(a+cur, (*ac)-cur, sizeof(trip), cmpT);
    if(cmpT(&a[cur], &a[*ac-1])!=0){
      for (int i = cur; i < *ac; i++) {
        a[i].second.first = cur;
        a[i].second.second = *ac;
      }
    }
    (*pos)++;
  }
}
Example #4
0
int main()
{
	int n,sum1,sum2;
	for(n = 1;n<20000;n++)
	{
		sum1 = process1(n);
		sum2 = process2(n);
		if(sum1 != sum2)
			printf("%d  %d  %d\n",n,sum1,sum2);
	}
	return 0;
}
Example #5
0
	void process( array * base ) {
		if ( base->k > MAXK )
			return;

		process1( base );
		
		if ( base->t < MAXT ) {
			process2( base );
		}

		process3( base );
	}
Example #6
0
//This method creates process to run process2 by forking the current process.
void createProcess2(){
	pid_t childPID;
	//Forks another process, for process2 which replaces **  with ^
	switch(childPID = fork()){
		//checks if forked successfully
		case -1:
			perror("fork failed");
			exit(EXIT_FAILURE);
		//closes the appropriate pipes and calls process2
		case 0:
			close(pipe1[0]);
			close(pipe1[1]);
			close(pipe2[1]);
			close(pipe3[0]);
			process2(pipe2[0],pipe3[1]);
			break;
		//Parent continues to fork for the last process, by calling a function to create
		//process for writeOut and it then waits for child process.
		default:
			createWriteOut();
			wait();
	}
}
Example #7
0
void ViBenchMarker3::process1(bool generate)
{
	QObject::disconnect(mCurrentObject.data(), SIGNAL(decoded()), this, SLOT(process1()));

	if(generate)
	{
		ViNoiseCreator creator;
		creator.createNoise(mCurrentObject->buffer(ViAudio::Target), mCurrentObject->buffer(ViAudio::Corrupted), mCurrentObject->buffer(ViAudio::CustomMask), mCurrentObject->buffer(ViAudio::Custom));
	}
	mCurrentObject->clearBuffer(ViAudio::Target);
	mCurrentObject->clearBuffer(ViAudio::Noise);
	mCurrentObject->clearBuffer(ViAudio::NoiseMask);

	/*if(mParamsStart.size() == 1) mDetector->setParameters(mParamsCurrent[0]);
	else if(mParamsStart.size() == 2) mDetector->setParameters(mParamsCurrent[0], mParamsCurrent[1]);
	else if(mParamsStart.size() == 3) mDetector->setParameters(mParamsCurrent[0], mParamsCurrent[1], mParamsCurrent[2]);
	else if(mParamsStart.size() == 4) mDetector->setParameters(mParamsCurrent[0], mParamsCurrent[1], mParamsCurrent[2], mParamsCurrent[3]);
	//else { cout << "Invalid parameter count of "<<mParamsStart.size()<<". Min: 1, Max: 4" << endl; quit(); }*/

	QObject::connect(mCurrentObject.data(), SIGNAL(noiseGenerated()), this, SLOT(process2()));
	mTime.restart();
	mCurrentObject->generateNoiseMask(mDetector);
}
Example #8
0
void FeatPyramid::featpyramid (const IplImage *im, const Model *model, int padX, int padY)
{
  float sbin, interval;
  float sc;
  int imsize[2];
  float maxScale;
  IplImage *imAux = NULL;
  int pad[3];

  if (padX == -1 && padY == -1)
  {
    padX = getPaddingX(model);
    padY = getPaddingY(model);
  }

  sbin = (float)model->getSbin();
  interval = (float) model->getInterval()+1.0;
  sc = pow (2, 1/(interval));
  imsize[0] = im->height;
  imsize[1] = im->width;
  maxScale = 1 + floor ( log ( min (imsize[0], imsize[1]) /
  (5*sbin) ) / log(sc) );

  // It is the number of elements that will contain pyramid->features
  // and pyramid->scales. At less must be 2*interval
  if ( (maxScale + interval) < (2*interval) )
    setDim (int(2*interval));

  else
    setDim (int(maxScale + interval));

  assert (getDim() > 0);
//  _feat = new CvMatND* [getDim()];    // Suspicious
  _feat.reserve(getDim());
  for (int i = 0; i < getDim(); i++) // Pre-allocate memory
	  _feat.push_back(cv::Mat());
//  assert (_feat != NULL);
  assert(!_feat.empty());
  _scales = new float [getDim()]; // Suspicious
  assert (_scales != NULL);

  // Field imsize is setted
  assert (imsize[0] > 0);
  assert (imsize[1] > 0);

  setImSize (imsize);
//cout << "Antes de bucle featpyramid" << endl;
  for (int i = 0; i < interval; i++)
  {
    // Image is resized
    imAux = resize (im, (1/pow(sc, i)));

    // "First" 2x interval
    //setFeat(process(imAux, sbin/2), i);
	setFeat(process2(imAux, sbin/2), i);
    setScales(2/pow(sc, i), i);

    // "Second" 2x interval
    //setFeat (process (imAux, sbin), (int)(i+interval));
	setFeat (process2 (imAux, sbin), (int)(i+interval));
    setScales (1/pow(sc, i), (int)(i+interval));

    // Remaining intervals
    IplImage *imAux2; // mjmarin added
    for (int j = (int)(i+interval); j < (int)maxScale; j = j+(int)interval)
    {
      // mjmarin: memory leak fixed
      //imAux = resize (imAux, 0.5); // Old sentence
      imAux2 = resize (imAux, 0.5);
      cvReleaseImage(&imAux);
      imAux = imAux2;

      //setFeat (process (imAux, sbin), (int)(j+interval));
	  setFeat (process2 (imAux, sbin), (int)(j+interval));
      setScales ((float)(0.5 * getScales()[j]), (int)(j+interval));
    }

    // mjmarin: more release needed for imAux
    cvReleaseImage(&imAux);
  }
  // Second loop
  for (int i = 0; i < getDim(); i++ )
  {
    // Add 1 to padding because feature generation deletes a 1-cell
    // Wide border around the feature map
    pad[0] = padY + 1;
    pad[1] = padX + 1;
    pad[2] = 0;    
    
    //CvMatND* tmpfeat = getFeat()[i];
	cv::Mat tmpfeat = getFeat()[i];
	CvMatND tmpND = tmpfeat;
    //CvMatND* tmppad = padArray (tmpfeat, pad, 0);
	CvMatND* tmppad = padArray (&tmpND, pad, 0);
    setFeat (tmppad, i);
    //cvReleaseMatND(&tmpfeat); // mjmarin: commented out since it should be auto released with use of cv::Mat
    

    // Write boundary occlusion feature
	cv::Mat fMat = getFeat()[i];
    for (int j = 0; j <= padY; j++)
      //for (int k = 0; k < getFeat()[i]->dim[1].size; k++)
	  for (int k = 0; k < fMat.size.p[1]; k++)
        //cvSetReal3D (getFeat()[i], j, k, 31, 1);
		fMat.at<double>(j, k, 31) = 1;

    //for (int j = getFeat()[i]->dim[0].size - padY -1; j < getFeat()[i]->dim[0].size; j++)
	for (int j = fMat.size.p[0] - padY -1; j < fMat.size.p[0]; j++)
      //for (int k = 0; k < getFeat()[i]->dim[1].size; k++)
	  for (int k = 0; k < fMat.size.p[1]; k++)
        //cvSetReal3D (getFeat()[i], j, k, 31, 1);
		fMat.at<double>(j, k, 31) = 1;

    //for (int j = 0; j < getFeat()[i]->dim[0].size; j++)
	for (int j = 0; j < fMat.size.p[0]; j++)
      for (int k = 0; k <= padX; k++)
        //cvSetReal3D (getFeat()[i], j, k, 31, 1);
		fMat.at<double>(j, k, 31) = 1;

    //for (int j = 0; j < getFeat()[i]->dim[0].size; j++)
	for (int j = 0; j < fMat.size.p[0]; j++)
      //for (int k = getFeat()[i]->dim[1].size - padX - 1; k < getFeat()[i]->dim[1].size; k++)
	  for (int k = fMat.size.p[1] - padX - 1; k < fMat.size.p[1]; k++)
        //cvSetReal3D (getFeat()[i], j, k, 31, 1);
		fMat.at<double>(j, k, 31) = 1;
  }

  setPadX (padX);
  setPadY (padY);
}
Example #9
0
/* -----------------------------------------------------------------------------
 * Define test script here.
 */
void TestCase::runTest( void ) {

/* ------------------------------ */

    UT_START_STEP( 1 );

    unsigned type = 0;
    Process process( type );
    UT_COMMENT( "Checking default values after object instantiation...\n" );

    UT_CHECK_OUTPUT( type == process.getType() );
    UT_CHECK_OUTPUT( false == process.isDead() );
    UT_CHECK_OUTPUT( false == process.isPaused() );
    UT_CHECK_OUTPUT( false == process.isAttached() );
    UT_CHECK_OUTPUT( false == process.initRequired() );
    UT_CHECK_OUTPUT( true == process.isActive() );
    UT_CHECK_OUTPUT( NULL == process.getNext() );

    UT_END_STEP;

/* ------------------------------ */

    UT_START_STEP( 2 );

    unsigned type = 0;
    Process process( type );
    UT_COMMENT( "Checking default setters and getters...\n" );

    UT_CHECK_OUTPUT( 0 == process.getType() );
    process.setType( 1 );
    UT_CHECK_OUTPUT( 1 == process.getType() );

    process.setActive( false );
    UT_CHECK_OUTPUT( false == process.isActive() );
    process.setActive( true );
    UT_CHECK_OUTPUT( true == process.isActive() );

    process.setAttached( true );
    UT_CHECK_OUTPUT( true == process.isAttached() );
    process.setAttached( false );
    UT_CHECK_OUTPUT( false == process.isAttached() );

    process.togglePause();
    UT_CHECK_OUTPUT( true == process.isPaused() );
    process.togglePause();
    UT_CHECK_OUTPUT( false == process.isPaused() );

    Process process2( 0 );
    process.setNext( &process2 );
    UT_CHECK_OUTPUT( &process2 == process.getNext() );
    process.setNext( NULL );
    UT_CHECK_OUTPUT( NULL == process.getNext() );

    process.kill();
    UT_CHECK_OUTPUT( true == process.isDead() );

    UT_END_STEP;

/* ------------------------------ */

    UT_START_STEP( 3 );

    UT_COMMENT( "Checking default Process::onUpdate() method...\n" );

    static bool on_initialize_called = false;

    class FooProcess : public Process {
    public:
        FooProcess( unsigned type ) : Process( type ) {
            m_InitRequired = true; }

        // Overwrite onInitialize
    protected:
        virtual void onInitialize( void ) {
            on_initialize_called = true;
        }
    };

    Process process( 0 );
    UT_CHECK_OUTPUT( false == process.initRequired() );
    process.onUpdate( 0 );
    UT_CHECK_OUTPUT( false == on_initialize_called );

    FooProcess fooprocess( 0 );
    UT_CHECK_OUTPUT( true == fooprocess.initRequired() );
    fooprocess.onUpdate( 0 );
    UT_CHECK_OUTPUT( true == on_initialize_called );
    UT_CHECK_OUTPUT( false == fooprocess.initRequired() );

    UT_END_STEP;

/* ------------------------------ */

    return;
}
Example #10
0
void ViBenchMarker3::process2()
{
	int time = mTime.elapsed();
	QObject::disconnect(mCurrentObject.data(), SIGNAL(noiseGenerated()), this, SLOT(process2()));

	/*QObject::connect(mCurrentObject.data(), SIGNAL(encoded()), this, SLOT(quit()));
	mCurrentObject->encode(ViAudio::Noise);
	return;*/

	qreal maxMAT = 0;
	qint64 maxTP = 0, maxTN = 0, maxFP = 0, maxFN = 0;
	qint64 i, lengthIndex, offset1 = 0, offset2 = 0;
	int noChange = 0;

	ViAudioReadData corrupted(mCurrentObject->buffer(ViAudio::Noise));
	ViAudioReadData realMask(mCurrentObject->buffer(ViAudio::CustomMask));
	ViAudioReadData length(mCurrentObject->buffer(ViAudio::Custom));
	corrupted.setSampleCount(WINDOW_SIZE);
	realMask.setSampleCount(WINDOW_SIZE);
	length.setSampleCount(WINDOW_SIZE);

	ViSampleChunk *nData1 = new ViSampleChunk(corrupted.bufferSamples() / 2);
	ViSampleChunk *nData2 = new ViSampleChunk(corrupted.bufferSamples() / 2);
	ViSampleChunk *nMask1 = new ViSampleChunk(corrupted.bufferSamples() / 2);
	ViSampleChunk *nMask2 = new ViSampleChunk(corrupted.bufferSamples() / 2);
	ViSampleChunk *nRealMask1 = new ViSampleChunk(realMask.bufferSamples() / 2);
	ViSampleChunk *nRealMask2 = new ViSampleChunk(realMask.bufferSamples() / 2);
	ViSampleChunk *nLength1 = new ViSampleChunk(corrupted.bufferSamples() / 2);
	ViSampleChunk *nLength2 = new ViSampleChunk(corrupted.bufferSamples() / 2);

	while(corrupted.hasData() && realMask.hasData())
	{
		corrupted.read();
		ViSampleChunk &corrupted1 = corrupted.splitSamples(0);
		ViSampleChunk &corrupted2 = corrupted.splitSamples(1);

		realMask.read();
		ViSampleChunk &realMask1 = realMask.splitSamples(0);
		ViSampleChunk &realMask2 = realMask.splitSamples(1);

		length.read();
		ViSampleChunk &length1 = length.splitSamples(0);
		ViSampleChunk &length2 = length.splitSamples(1);

		for(i = 0; i < corrupted1.size(); ++i)
		{
			(*nData1)[i + offset1] = corrupted1[i];
			(*nRealMask1)[i + offset1] = realMask1[i];
			(*nLength1)[i + offset1] = length1[i];
		}
		offset1 += corrupted1.size();
		for(i = 0; i < corrupted2.size(); ++i)
		{
			(*nData2)[i + offset2] = corrupted2[i];
			(*nRealMask2)[i + offset2] = realMask2[i];
			(*nLength2)[i + offset2] = length2[i];
		}
		offset2 += corrupted2.size();
	}

	mCurrentObject->clearBuffer(ViAudio::Target);
	mCurrentObject->clearBuffer(ViAudio::Noise);
	mCurrentObject->clearBuffer(ViAudio::NoiseMask);

	ViNoise noise1(nData1, nMask1, mCurrentThreshold);
	ViNoise noise2(nData2, nMask2, mCurrentThreshold);

	QVector<qreal> lengthTP(ViNoiseCreator::noiseSizeCount());
	QVector<qreal> lengthFN(ViNoiseCreator::noiseSizeCount());
	lengthTP.fill(0);
	lengthFN.fill(0);
	QVector<qreal> maxLengthTP, maxLengthFN;

	for(mCurrentThreshold = MASK_START; mCurrentThreshold <= MASK_END; mCurrentThreshold += MASK_INTERVAL)
	{
		noise1.setThreshold(mCurrentThreshold);
		noise1.generateMask(ViNoise::NOISE_TYPE);
		noise2.setThreshold(mCurrentThreshold);
		noise2.generateMask(ViNoise::NOISE_TYPE);

		qint64 truePositives = 0, falsePositives = 0, trueNegatives = 0, falseNegatives = 0;

		for(i = 0; i < nRealMask1->size(); ++i)
		{
			if((*nRealMask1)[i] == 1)
			{
				lengthIndex = ViNoiseCreator::fromSizeMask((*nLength1)[i]) - 1;
				if((*nMask1)[i] == 1)
				{
					++truePositives;
					lengthTP[lengthIndex] += 1;
				}
				else
				{
					++falseNegatives;
					lengthFN[lengthIndex] += 1;
				}
			}
			else if((*nRealMask1)[i] == 0)
			{
				if((*nMask1)[i] == 1) ++falsePositives;
				else ++trueNegatives;
			}
		}

		for(i = 0; i < nRealMask2->size(); ++i)
		{
			if((*nRealMask2)[i] == 1)
			{
				lengthIndex = ViNoiseCreator::fromSizeMask((*nLength2)[i]) - 1;
				if((*nMask2)[i] == 1)
				{
					++truePositives;
					lengthTP[lengthIndex] += 1;
				}
				else
				{
					++falseNegatives;
					lengthFN[lengthIndex] += 1;
				}
			}
			else if((*nRealMask2)[i] == 0)
			{
				if((*nMask2)[i] == 1) ++falsePositives;
				else ++trueNegatives;
			}
		}

		qreal math = matthews(truePositives, trueNegatives, falsePositives, falseNegatives);
		if(math > maxMAT)
		{
			maxMAT = math;
			maxTP = truePositives;
			maxTN = trueNegatives;
			maxFP = falsePositives;
			maxFN = falseNegatives;
			maxLengthTP = lengthTP;
			maxLengthFN = lengthFN;
			noChange = 0;
		}
		++noChange;
		if(noChange > NO_CHANGE) break;
	}

	delete nRealMask1;
	delete nRealMask2;
	delete nLength1;
	delete nLength2;

	++mDoneParamIterations;
	if(maxMAT > mBestMatthews) mBestMatthews = maxMAT;
	printFileData(time, maxTP, maxTN, maxFP, maxFN, maxLengthTP, maxLengthFN);
	printTerminal(time, maxTP, maxTN, maxFP, maxFN, mBestMatthews);

	if(nextParam()) process1(false);
	else nextFile();
}
Example #11
0
static 
#endif
void traverseLcpTree(Int64 *lcpTab, Int64 *sa, Sequence *seq, Int64 numOfSubjects, Int64 numOfQueries, Int64 *seqBorders
											, Int64 *leftBorders, Int64 *strandBorders
											, queryInterval ***listQueryIntervalsFwd // lists of query intervals, there are |Q| lists
											, queryInterval ***listQueryIntervalsRev // lists of query intervals, there are |Q| lists
											, Int64 maxDepth, Int64 *maxShulens
											, queryInterval ***fastSearch, Int64 *lastIndex, qNode ***root) {

  Interval *lastInterval, *interval;
  Int64 i, j, lb, rightEnd, lastIsNull;
  //Int64 numOfChildren;
  Stack *treeStack = NULL;
	Stack *reserveStack = NULL; // reserve stack for intervals
	Stack *reserveQIStack = NULL; // reserve stack for query intervals
	short *QS; /* array of subject and query indexes corresponding to each position in the SA; pos. values --> subjects, neg.values --> queries */
	
	//queryLeaves - maximal number is the maximal number of leaves at each interval; queryLeaves[i][0]-query index, queryLeaves[i][1]-position in a query
	Int64 queryLeaves[MAXNUMLEAVES][2]; //queryLeaves[i][0]-query index, queryLeaves[i][1]-position in a query
	int maxCols = 2;
	int step = STEP; 
	queryInterval *qi = NULL; 
	qNode *qn = NULL;

	// unresolvedQLeaves - unresolved leaves from the interval's subtree; unresolvedQLeaves[i][0]-query index, unresolvedQLeaves[i][1]-position in a query
	Int64 *unresolvedQLeaves = NULL;
	Int64 maxUnresQLeaves = 100;
	unresolvedQLeaves = emalloc(maxUnresQLeaves * sizeof(Int64) * 2); // * 2 since each leaf is represented by ints query index and a position within a query

	/* allocate 2 lists of |Q| pointers; one list is the beginning and the other is end of the list */
	if (BSEARCH) {
		*root = getBTQueryIntervals(numOfQueries);
	}
	else {
		*listQueryIntervalsFwd = getListQueryIntervals(numOfQueries);
		*listQueryIntervalsRev = getListQueryIntervals(numOfQueries);	
	}

	/* initialize auxiliary arrays: subjects and queryLeaves */
  QS = getQS(seqBorders, leftBorders, numOfSubjects, numOfQueries, step);
	//queryLeaves = getQueryLeaves(&numQueryLeaves, &maxNumLeaves);
	
  sa++; /* since data in sa and lcpTab start with position 1, and not 0 */
  lcpTab++;	
  rightEnd = seq->len-1; 
  lcpTab[0] = 0; /* or -1 */

  treeStack = createStack();    /* true stack */
  lastIsNull = 1; 
  lastInterval = NULL;
  interval = NULL;
  push(treeStack, getInterval(0, 0, rightEnd, NULL, numOfSubjects, NULL, maxDepth)); /* push root node to the stack */

  /* auxiliary stack for (Interval *); used for saving used allocated locations; since stack operations pop/push are faster than malloc */
	reserveStack = createStack(); 
  
	/* auxiliary stack for (queryInterval *) */
	reserveQIStack = createStack(); 

	for (i = 1; i < seq->len; i++){
    lb = i - 1;
    while(lcpTab[i] < ((Interval *)(treeStack->top))->lcp) { /* end of the previous interval, so the interval should be popped from the stack*/						
			/* if the current top is the child of the new node, then pop the top */			
      ((Interval *)(treeStack->top))->rb = i - 1;
      lastInterval = (Interval *)pop(treeStack);			
			process2(lastInterval, *listQueryIntervalsFwd, *listQueryIntervalsRev, seqBorders, 
								leftBorders, strandBorders, numOfSubjects, QS, step, &queryLeaves[0][0], maxCols, sa, &unresolvedQLeaves, 
								&maxUnresQLeaves, reserveQIStack, maxShulens, fastSearch, lastIndex, *root); 			
			
			lb = lastInterval->lb;

			/* save child intervals of popped interval */
      for(j = 0; j < lastInterval->numChildren; j ++) {
				lastInterval->children[j]->numChildren = 0;
				lastInterval->children[j]->parent = NULL;
				push(reserveStack, (void *)lastInterval->children[j]);
      }
      lastIsNull = 0;
			if (lcpTab[i] <= ((Interval *)treeStack->top)->lcp) { /* the new top is the parent of the ex top*/
				lastInterval->parent = treeStack->top;
				addChild((Interval *)treeStack->top, lastInterval);
				lastIsNull = 1;
			}			
    } /* end while */

 		if (lcpTab[i] > ((Interval *)treeStack->top)->lcp) { /* add interval to the stack */
			if (isEmpty(reserveStack)) { 
				//interval = getInterval(lcpTab[i], lb, rightEnd, NULL, numOfSubjects, treeStack->top, maxDepth);// treeStack->top or null
				interval = getInterval(lcpTab[i], lb, rightEnd, NULL, numOfSubjects, NULL, maxDepth);
			}
			else { /* use locations from the reserveStack */ 
				interval = pop(reserveStack); // pop the last child of the lastInterval from the reservestack
				interval->lcp = lcpTab[i];
				interval->lb = lb;
				interval->rb = rightEnd;
				interval->numChildren = 0;
				interval->parent = NULL;
      }
      if (!lastIsNull){ 
				lastInterval->parent = interval;
				addChild(interval, lastInterval);
				lastIsNull = 1;
      }
      push(treeStack, interval);
    }
  }

#if DEBUG  
	printf("Empting stack...\n");
	printf("Number of intervals allocated:%lld\n\n", (long long)numInterval);
#endif

	while(!isEmpty(treeStack)) { 
    interval = pop(treeStack);    
		/* when the stack is not empty and the current interval has no parent, then his parent is on the top of the stack*/
		if (!isEmpty(treeStack) && !interval->parent && interval->lcp > ((Interval *)(treeStack->top))->lcp) { 
			interval->parent = treeStack->top;
			addChild((Interval *)treeStack->top, interval);
		}
		/* process: 
		 * 1) it labels an interval according to whether it has ST leaves from query (isQuery) or from subject (isSubject) or both (isQuery && isSubject).
		 * 2) if(isQuery && isSubject) it determines the corresponding query shustring lengths (if any) */
		process2(interval, *listQueryIntervalsFwd, *listQueryIntervalsRev, seqBorders, leftBorders, strandBorders, 
							numOfSubjects, QS, step, &queryLeaves[0][0], maxCols, sa, &unresolvedQLeaves, 
							&maxUnresQLeaves, reserveQIStack, maxShulens, fastSearch, lastIndex, *root); 			

		for (i = 0; i < interval->numChildren; i++) {
			freeInterval((void *)interval->children[i]);
		}
		interval->numChildren = 0;
		if (!interval->parent) {
			freeInterval((void *)interval); 
		}
	}  
	//freeInterval((void *)interval); /* free the root interval; it has to be done here, what is different from kr 2!! */
  freeStack(treeStack, freeInterval);
  
	/* free memory allocated for the reserveStack */
	while (!isEmpty(reserveStack)) {
    interval = pop(reserveStack);
		for (i = 0; i < interval->numChildren; i++) {
			freeInterval((void *)interval->children[i]);
		}
    //freeInterval((void *)interval); /* free the root interval */
		if (!interval->parent) {
			freeInterval((void *)interval); 
		}
  }
	/* free reserve stack */
	freeStack(reserveStack, freeInterval);

	/* free reserve queryInterval stack */
	if (BSEARCH) {
		while (!isEmpty(reserveQIStack)) {
			qn = pop(reserveQIStack);
			qn->left = qn->right = NULL;
			freeQNode(qn); 
		}
		freeStack(reserveQIStack, freeQNode);
	
	}
	else {
		while (!isEmpty(reserveQIStack)) {
			qi = pop(reserveQIStack);
			qi->next = qi->prev = NULL;
			freeQueryInterval(qi); 
		}
		freeStack(reserveQIStack, freeQueryInterval);
	}

#if DEBUG  
	printf("Finished.. Number of intervals allocated:%lld\n\n", (long long)numInterval);
#endif
	
	free(QS);
	free(unresolvedQLeaves);
	//printf("maxUnresQLeaves = %d\n", maxUnresQLeaves);
}