示例#1
0
void FreeSuffixTreeEulerTour(SuffixTreeEulerTour *eulerTour)
{
    if (!eulerTour)
        return;
        
    FreeDynamicArray(eulerTour->dfsToNode);
    FreeDynamicArray(eulerTour->dfsDepths);
    
    MemFree(eulerTour->rankToDfs);
    MemFree(eulerTour);
}
示例#2
0
void Entrada::arquivo(const char* arquivo) {

	vec qtdPontos;
	contaPontos(arquivo, &qtdPontos);
	//printf("Arquivo:");

	FILE *p;
	p = fopen(arquivo, "r");
	GLint curvaAtual = 0, pontoAtual = 0;
	bool pupila = false;
	while (!feof(p)) {

		char c, str[80];
		float f;
		fscanf(p, "%c", &c);
		//printf("%c",c);
		if (c == 'w')
			pupila = true;
		if (c == '{') //nova curva
				{
			pontos = AllocateDynamicArray(qtdPontos.at(curvaAtual));
			pontoAtual = 0;
		} else if (!feof(p) && c == '}') //fim da curva
				{
			//imprimePontos("Confere", pontos, qtdPontos[curvaAtual]);
			if (!pupila) desenha->desenhaCurva(pontos, qtdPontos[curvaAtual]);
			FreeDynamicArray(pontos, qtdPontos[curvaAtual]);
			curvaAtual++;
		} else if (c == '(') //novo ponto
				{
			GLfloat x;
			//X
			fscanf(p, "%f", &x);
			pontos[pontoAtual][0] = x;
			//virgula
			fscanf(p, "%c", &c);
			//Y
			GLfloat y;
			fscanf(p, "%f", &y);
			pontos[pontoAtual][1] = y;
			//Z
			pontos[pontoAtual][2] = 0.0;
			pontoAtual++;
			if (pupila) {

				desenha->desenhaCirculo(x, y);
			}
		}
	}


	fclose(p);

}
示例#3
0
int AppendSubtreeToSuffixTree(SuffixTree *st, int parent, int childOrder, SuffixTree *srcTree, int srcSubTreeRoot, int rootFrom)
{
    DynamicArray *childStack = CreateDynamicArray(1);
    SuffixTreeNode *srcNode = &(srcTree->nodes[srcSubTreeRoot]);
    PushToDynamicArray(childStack, childOrder);
    
    int cur = AppendChildToSuffixTreeNode(st, parent, childOrder, rootFrom, srcNode->depth, srcNode->leaf, srcNode->childrenCount, NULL);
    int root = cur;
    PushToDynamicArray(childStack, 0);
    
    while (1)
    {
        if (*LastInDynamicArray(childStack) < st->nodes[cur].childrenCount)
        {
            srcNode = &(srcTree->nodes[srcNode->children[*LastInDynamicArray(childStack)]]);
            int from = srcNode->from;
            
            // skip 'em
            while (srcNode->childrenCount == 1 && srcNode->leaf == -1)
            {
                int child = srcNode->children[0];
                srcTree->nodes[srcNode->parent].children[*LastInDynamicArray(childStack)] = child;
                srcTree->nodes[child].parent = srcNode->parent;
                
                srcNode = &(srcTree->nodes[child]);
            }
                
            cur = AppendChildToSuffixTreeNode(st, cur, *LastInDynamicArray(childStack), from, srcNode->depth, srcNode->leaf, srcNode->childrenCount, NULL);
            PushToDynamicArray(childStack, 0);
        }
        else
        {
            if (st->nodes[cur].parent == parent)
                break;
            
            srcNode = &(srcTree->nodes[srcNode->parent]);
            cur = st->nodes[cur].parent;
            
            PopFromDynamicArray(childStack);
            ++(*LastInDynamicArray(childStack));
        }        
    }
    
    FreeDynamicArray(childStack);
    return root;
}
示例#4
0
SuffixArray *CreateSuffixArrayFromSuffixTree(SuffixTree *st)
{
    DynamicArray *childStack = CreateDynamicArray(1);
    int i = 0, ch = 0, j = 0, d = -1, n = st->leavesCount;
    int *a = malloc((n + 1) * sizeof *a),
        *lcp = malloc(n * sizeof *lcp);
        
    while (j < n)
    {
        if (ch < st->nodes[i].childrenCount)
        {
            PushToDynamicArray(childStack, ch);
            i = st->nodes[i].children[ch];
            ch = 0;        
        }
        else
        {
            if (st->nodes[i].leaf != -1)
            {
                a[j] = st->nodes[i].leaf;
                if (j > 0) 
                    lcp[j - 1] = d;
                ++j;
            }
            
            i = st->nodes[i].parent;
            ch = PopFromDynamicArray(childStack) + 1;
            d = st->nodes[i].depth;
        }
    }
    a[n] = n;
    lcp[n-1] = 0;
    
    // free resources
    FreeDynamicArray(childStack);
    
    return CreateSuffixArray(lcp, a, n);
}
示例#5
0
int main(int argc, char* argv[]){

	// Input for initial condition 
	input* 	inputData = new input;

	// Read input file
	inputData->readInputFile();
	
	N = inputData->getN();				// Number of CVs
	CFL = inputData->getCFL();			// CFL Number
	double h = 1.0/N;			 	// delta x	
	double curr_time = 0;				// Keep track of current time
	int count=0;					// Count for no. of time steps
	int M = 3*N/CFL;				// Estimated number of time-levels
	
	// Allocate the arrays 
	double** w = AllocateDynamicArray(3,N);		// State vector
	double** f = AllocateDynamicArray(3,N);		// Flux vector
	double** rho = AllocateDynamicArray(M,N);	// Density
	double** E = AllocateDynamicArray(M,N);		// Total energy 
	double** e = AllocateDynamicArray(M,N);		// Specific internal energy
	double** p = AllocateDynamicArray(M,N);		// Pressure
	double** Mach = AllocateDynamicArray(M,N);	// Mach Number
	double** u = AllocateDynamicArray(M,N);		// Velocity

	//Initial condition
	Initialize_w(inputData,w,h);
	Initialize_f(inputData,f,h);

	cout << "\nInitial time step: "<<tau(w,h)<<endl;

	//Calculation of w at next time steps
	while(curr_time<=inputData->getTime()){

		//Current time
		curr_time = curr_time + tau(w,h);
		
		//Solve for vector w
		solve(inputData, w, f, h);
	
		//Update vector f with new values of vector w
		update_f(f,w);
		
		//Extract flow variables from vector w
		for(int j=0;j<N;j++){
			rho[count][j] = w[0][j];
			u[count][j] = w[1][j]/rho[count][j];
			E[count][j] = w[2][j];
			p[count][j] = 0.4*(E[count][j] - 0.5*rho[count][j]*u[count][j]*u[count][j]);
			e[count][j] = w[2][j]/rho[count][j] - 0.5*u[count][j]*u[count][j];
			Mach[count][j] = u[count][j]/SQRT(1.4*p[count][j]/rho[count][j]);
		}

		//Count number of time steps
		count++;	

		cout<<"\nTime step No. : "<<count<<"\tTime = "<<curr_time<<endl;
	}
	
	PrintFlowVariables(inputData, rho, u, E, e, p, Mach, count, h);

	cout<<"\nNumber of time steps = "<<count<<endl;
	cout<<"\nCurrent time = "<<curr_time<<endl;

	FreeDynamicArray(w);
	FreeDynamicArray(f);
	FreeDynamicArray(rho);
	FreeDynamicArray(E);
  FreeDynamicArray(e);
	FreeDynamicArray(p);
	FreeDynamicArray(u);
	FreeDynamicArray(Mach);
	delete inputData;

return 0;
}
示例#6
0
SuffixTree *CreateSuffixTreeFromSuffixArray(SuffixArray *sa, int strLen)
{
    int n = sa->n;
    int *lcp = sa->lcp, *a = sa->a;
    
    SuffixTree *st = CreateSuffixTree(2 * n, 1);
    DynamicArray *childrenCountersBuffer = CreateDynamicArray(1), *childrenBuffer = CreateDynamicArray(1);
    
    // root
    PushToDynamicArray(childrenCountersBuffer, 0);
    
    // add first leaf node
    int j = CreateAndInitializeNextSuffixTreeNode(st, 0, a[0], strLen - a[0], a[0]);
    AddChildToBufferAndMakeItCurrent(childrenCountersBuffer, childrenBuffer, j);
        
    int i = 0;   
    while (i < n - 1)
    {
        // we go over suffix array and
        // every step we start in some node with index j and : 
        //  * lcp < current depth ==> goes up until lcp < current depth. 
        //      At the end insert inner node if needed (there's no node with depth = lcp)
        //  * lcp > current depth ==> add new inner node as a child
        // now we stand at node with depth = lcp, so just add leaf node
        
        if (st->nodes[j].depth < lcp[i])
        {
            // add inner node with lcp depth;
            j = CreateAndInitializeNextSuffixTreeNode(st, j, a[i + 1], lcp[i], -1);
            AddChildToBufferAndMakeItCurrent(childrenCountersBuffer, childrenBuffer, j);
        }
        else if (st->nodes[j].depth > lcp[i])
        {
            int child;
            do
            {
                CompleteSuffixTreeNodeConstruction(&st->nodes[j], childrenCountersBuffer, childrenBuffer);
                child = j;
                j = st->nodes[j].parent;
            }
            while (st->nodes[j].depth > lcp[i]);
            
            if (st->nodes[j].depth < lcp[i])
            {
                // insert node
                
                int childSuffixIndex = st->nodes[child].from - st->nodes[j].depth;
             
                j = CreateAndInitializeNextSuffixTreeNode(st, j, childSuffixIndex, lcp[i], -1);
                
                // fix old parent of @child
                *LastInDynamicArray(childrenBuffer) = j;
                // fix @child
                st->nodes[child].parent = j;
                st->nodes[child].from = childSuffixIndex + lcp[i];
                
                // push @child to j children
                PushToDynamicArray(childrenCountersBuffer, 1);
                PushToDynamicArray(childrenBuffer, child);
            }
        }
        
        // add leaf node depth;
        if (lcp[i] < strLen - a[i + 1])
        {
            j = CreateAndInitializeNextSuffixTreeNode(st, j, a[i + 1], strLen - a[i + 1], a[i + 1]);
            AddChildToBufferAndMakeItCurrent(childrenCountersBuffer, childrenBuffer, j);
        }
        else
        {
            // inner leaf node
            st->nodes[j].leaf = a[i + 1];
        }
            
        ++i;
    }
    
    // complete remaining nodes
    while (childrenCountersBuffer->count > 0)
    {
        CompleteSuffixTreeNodeConstruction(&st->nodes[j], childrenCountersBuffer, childrenBuffer);
        j = st->nodes[j].parent;
    }
    
    st->suffixArray = sa;
    st->leavesCount = n;
    
    // free resources
    FreeDynamicArray(childrenBuffer);
    FreeDynamicArray(childrenCountersBuffer);
    
    return st;
}