Exemplo n.º 1
0
void SPA(
                      /* The tree */
                      SUFFIX_TREE*    tree,            
                      /* Current node */
                      POS*            pos,            
                      /* Current phase number */
                      DBL_WORD        phase,            
                      /* The last extension performed in the previous phase */
                      DBL_WORD*       extension,         
                      /* 1 if the last rule applied is 3 */
                      char*           repeated_extension)   
{
   /* No such rule (0). Used for entering the loop */
   DBL_WORD   rule_applied = 0;   
   PATH       str;
   
   /* Leafs Trick: Apply implicit extensions 1 through prev_phase */
   tree->e = phase+1;

   /* Apply explicit extensions untill last extension of this phase is reached 
      or extension rule 3 is applied once */
   while(*extension <= phase+1)            
   {
      str.begin       = *extension;
      str.end         = phase+1;
      
      /* Call Single-Extension-Algorithm */
      SEA(tree, pos, str, &rule_applied, *repeated_extension);
      
      /* Check if rule 3 was applied for the current extension */
      if(rule_applied == 3)
      {
         /* Signaling that the next phase's first extension will not follow a 
            suffix link because same extension is repeated */
         *repeated_extension = 1;
         break;
      }
      *repeated_extension = 0;
      (*extension)++;
   }
   return;
}
Exemplo n.º 2
0
int SPA(SuffixTree_T tree, struct SuffixTreePos* pos,
         SuffixTreeIndex_T phase, SuffixTreeIndex_T* extension,
         char* repeated_extension)
{
   /* No such rule (0). Used for entering the loop */
   SuffixTreeIndex_T   rule_applied = 0;
   struct SuffixTreePath       str;
   
   /* Leafs Trick: Apply implicit extensions 1 through prev_phase */
   tree->e = phase+1;

   /* Apply explicit extensions untill last extension of this phase is reached 
      or extension rule 3 is applied once */
   while(*extension <= phase+1)            
   {
      str.begin       = *extension;
      str.end         = phase+1;
      
      /* Call Single-Extension-Algorithm */
      int ret_val = SEA(tree, pos, str, &rule_applied, *repeated_extension);
      check(ret_val == 0, "Single Extension Algorithm failed.");
      /* Check if rule 3 was applied for the current extension */
      if(rule_applied == 3)
      {
         /* Signaling that the next phase's first extension will not follow a 
            suffix link because same extension is repeated */
         *repeated_extension = 1;
         break;
      }
      *repeated_extension = 0;
      (*extension)++;
   }
   return 0;

error:
   return 1;
}
Exemplo n.º 3
0
NODO *ukkonen(NODO* I, char *S, int m, int* e){
    int root_to;
    int matcheado=0;
    int i, j_i, j_estrella;	// i = fases j = extensiones
    int regla3 = 0;
    int reglaAnterior = 0;
    int faseInicial;
    int auxg=0;
//  estas variables se utilizan para hacer reglas 3 en el caso especial
    int k, p1, p2;  
    NODO* auxiliar; 
//    int auxj_i=0;
    NODO* nodoAnterior;
    if(flagString == 1){
        faseInicial = 1;
        *e = 0;
        root_to = 0;
        j_i = 1;
    
    /*------------Genero I(1)------------*/

        // Crear el root
        I = crearNodo(0, NULL, NULL, 0, &root_to, S);
        //Creamos el hijo
        *e = *e + 1;
        nodoAnterior = crearNodo(0, I, NULL, 1, e, S);
        nodoAnterior->posS1=1;
    }
    else{
         special_find(ST, &auxg, &matcheado);
//         printf("auxg: %d n->S1: %d n->S2: %d e: %d\n", auxg, nodoAnterior->posS1, nodoAnterior->posS2, matcheado);
//         printTotalString(nodoAnterior);
         //printSTree(ST,1);
         if(matcheado>=2){
					  p2=matcheado-1;
					 	for(k=2;k<=matcheado;k++){
							 p1=p2;
		           auxiliar=find_j_i_naive(ST, &p1, k, S2, 1);
		           calculaRegla(auxiliar, p1, k, i, S2);
						   p2--;
						}            
				 }		
         //printSTree(ST,1);				 
         *e = matcheado;
         faseInicial = matcheado;
         nodoAnterior=ST; // inicialmente empieza desde la raiz
         j_i = 0;
   
    }
    /*-----------Calculo I(i+1)-----------*/
    for (i = faseInicial; i <= (m - 1); i++) {	//Comienza Fase i+1
           /*----SPA---- */   //ver pag 106 Dan Gusfuield
     	  // paso 1
		regla1(e);
		reglaAnterior = 1;

 	 // paso 2
		while ((i + 1 > j_i) && (!regla3)){//mientras(no regla3 o hicimos todas las extnsiones
		    nodoAnterior =
                    SEA(I, nodoAnterior, j_i + 1, i, &regla3, &reglaAnterior, e, S);
		    						j_i++;
/*		    						if(reglaAnterior==3 && flagString==2 && auxj_i==0){
		    							 auxj_i=j_i;
		    						}*/
                    //printSTree(I, 1);
  		}
/*			if(auxj_i!=0 && flagString == 2){ //restauro el valor de j_i pues hice muchas veces regla 3
					j_i=auxj_i;
					auxj_i=0;
   		}
*/
	   	 if (regla3) {
		    j_estrella = j_i;
		    regla3 = 0;
		 }
		 else j_estrella = i + 2;
         //paso 3
	 j_i = j_estrella - 1;
	 if(i==faseInicial) flagSpecial = 0;
    }
    return (I);
}