int calculaRegla(NODO * nodoActual, int g, int j, int i, char *S) { int regla; char* Saux; if(esRaiz(nodoActual)) Saux = S; else{ if(nodoActual->posS1!=0 && nodoActual->posS2!=0) Saux=S1; else{ if(nodoActual->posS1!=0) Saux=S1; else Saux=S2; } } //para saber de quien es el from if ((longPath(nodoActual) == g) || esRaiz(nodoActual) || (g == 0)) {//#ver de reducir guarda if (nodoActual->hijos[s_i(S, i + 1)] != NULL) { regla = 3; if(flagString == 2 && longPath(nodoActual->hijos[s_i(S, i + 1)])==1 && (nodoActual->hijos[s_i(S, i + 1)]->posS2 == 0)){ nodoActual->hijos[s_i(S, i + 1)]->posS2=j; } } else regla = 20; } else{ if (s_i(S, i + 1) == s_i(Saux, nodoActual->from + g)){ regla = 3; if((flagString == 2) && (longPath(nodoActual) == (g+1)) && (nodoActual->posS2==0)) nodoActual->posS2=j; } else regla = 21; } return regla; }
NODO *find_j_i(NODO * nodoActual, int *g, int j, int i, char *S) { NODO *temp; int gprima, h; int posicion_absoluta_gamma; // posicion donde comienza gamma en el string S if (*g == 0){ return nodoActual;//Si longgamma = 0 } posicion_absoluta_gamma = i - *g; h = 1; temp = buscarHijo(nodoActual, posicion_absoluta_gamma + h, S); gprima = longPath(temp); if(flagString==2 && temp->posS2 == 0 && (*g>=gprima)){ temp->posS2 = j; } while (*g > gprima) { h = h + gprima; *g = *g - gprima; temp = buscarHijo(temp, posicion_absoluta_gamma + h, S); gprima = longPath(temp); if(flagString==2 && temp->posS2 == 0 && *g>=gprima){ temp->posS2 = j; } } return temp; }
NODO *special_find(NODO * arbol, int *g, int* matcheado) { NODO *temp; int j=1; int gprima; int auxletra; auxletra = s_i(S2, j); //printf("1 %d\n", auxletra); if (arbol->hijos[auxletra]!=NULL) temp = buscarHijo(arbol, j, S2); else return arbol; //printf("2\n"); gprima = longPath(temp); while(*matcheado+gprima<=strlen(S2)){ if(cmpString(temp->from, j, j+gprima-1, S1, S2)==gprima){ //printf("a\n"); temp->posS2 = 1; *matcheado=*matcheado+gprima; j=j+gprima; auxletra = s_i(S2, j); if (temp->hijos[auxletra]!=NULL){ //printf("a2\n"); temp = buscarHijo(temp, j, S2); gprima=longPath(temp); } else{ //printf("a3\n"); *g=gprima; return temp; } } else{ //printf("b\n"); *g=cmpString(temp->from, j, j+gprima-1, S1, S2); *matcheado=*matcheado+*g; return temp; } } //printf("3\n"); *g=cmpString(temp->from, j, strlen(S2), S1, S2); *matcheado=*matcheado+*g; return temp; }
NODO *find_j_i_naive(NODO * nodoActual, int *g, int j, char *S, int actualizoPosS2) { NODO *temp; int gprima,h=0; if (*g == 0) return nodoActual; // Si longBeta = 0... temp = buscarHijo(nodoActual, j, S); gprima = longPath(temp); if(flagString==2 && (temp->posS2 == 0) && (*g>=gprima) && actualizoPosS2 == 1){ temp->posS2 = j; } while (*g > gprima) { h = h + gprima; *g = *g - gprima; temp = buscarHijo(temp, j + h, S); gprima = longPath(temp); if(flagString==2 && temp->posS2 == 0 && *g>=gprima && actualizoPosS2 == 1){ temp->posS2 = j; } } return temp; }
void HFileSpec::SetNativePath(std::string inPath) { HWTStr path(inPath.c_str()); assert(HasUnicode()); unsigned long size = _MAX_PATH; unsigned long r; HAutoBuf<wchar_t> fullPath(new wchar_t[size]); wchar_t* filePart; size = ::GetFullPathNameW(path, size, fullPath.get(), &filePart); if (size > _MAX_PATH) { fullPath.reset(new wchar_t[size]); r = ::GetFullPathNameW(path, size, fullPath.get(), &filePart); if (r == 0 || r > size) THROW((::GetLastError(), true, true)); } unsigned long longSize = ::GetLongPathNameW(fullPath.get(), fullPath.get(), size); if (longSize == 0) longSize = size; else if (longSize > size) { HAutoBuf<wchar_t> longPath(new wchar_t[longSize]); r = ::GetLongPathNameW(fullPath.get(), longPath.get(), longSize); if (r == 0 || r > longSize) THROW((::GetLastError(), true, true)); fullPath.reset(longPath.release()); } fNativePath = Convert(UTF16String(fullPath.get())); if (fNativePath.compare(0, 8, "\\\\?\\UNC\\") == 0) fNativePath.erase(2, 6); else if (fNativePath.compare(0, 4, "\\\\?\\") == 0) fNativePath.erase(0, 4); }
// Esta es la impplementacion del Algoritmo SEA del libro del libro de Dan Gusfield (ver pag 100) NODO *SEA(NODO * I, NODO * nodoAnterior, int j, int i, int *regla3, int* reglaAnterior, int *e, char *S){ int regla; int g=-1; // variables utilizadas por skip/count trick int k, p1, p2; // a estas variables las uso para hacer las reglas tres en el arbol generalizado (con S2) NODO *nodoActual; NODO *nuevo; NODO *auxiliar; nuevo = NULL; //printf("\n\n\ningreso a SEA FASE : %d -- j: %d raglaAnt: %d - NodoExtAnt: ", i + 1, j, *reglaAnterior); //printTotalString(nodoAnterior); //printf("1\n"); //-----------------PASO 1 -----------------// //si el nodo de la extension anterior S[j-1..i+1] no tiene slink if (!(tiene_Slink(nodoAnterior))) { if(tiene_Slink(nodoAnterior->padre)){ //si no vengo de regla 2b-caso "sin slink" nodoActual = nodoAnterior->padre; g = longPath(nodoAnterior); } else{ nodoActual = I; } } else { nodoActual = nodoAnterior; g = 0; } //printf("2\n"); // printf("\nFin paso 1: g: %d - NodoActual: ", g); //printf("3\n"); // printTotalString(nodoActual); //printf("4\n"); //-----------------PASO 2 -----------------// if(!esRaiz(nodoActual)){ if(tiene_Slink(nodoActual)&&!esRaiz(nodoActual->slink)){ //printf("a\n"); if ((*reglaAnterior != 3 && flagString == 1) || ((flagString==2) && (((*reglaAnterior == 20 || *reglaAnterior == 21) && flagSpecial == 1) || (*reglaAnterior != 3 && flagSpecial == 0)))) g--; nodoActual = nodoActual->slink; if(flagString==2&&nodoActual->posS2==0) nodoActual->posS2=j; nodoActual = find_j_i(nodoActual, &g, j, i, S); } else{ g = i - j + 1; //find naive (no usa slink) nodoActual = find_j_i_naive(I, &g, j, S, 1); } } else{ g = i - j + 1; //find naive (no usa slink) nodoActual = find_j_i_naive(I, &g, j, S, 1); } //printf("5\n"); // printf("\nFin paso 2: g: %d - nodoActual:", g); //printf("6\n"); // printTotalString(nodoActual); //printf("7\n"); //-----------------PASO 3 -----------------// regla = calculaRegla(nodoActual, g, j, i, S); //printf("8\n"); // printf("\nEn Paso 3: regla a usar: %d\n", regla); nuevo = nodoActual; if (regla == 20) { nuevo = regla2a(nodoActual, j, i, e, S); } if (regla == 21) { nuevo = regla2b(nodoActual, g, j, i, e, S); if(tiene_Slink(nodoActual)){ if(longPath(nodoActual) == longPath(nodoActual->slink)){ (nuevo->padre)->slink = (nodoActual->slink)->padre; } } else{ g = i - j; nodoActual = find_j_i_naive(I, &g, j+1, S, 0); if (longPath(nodoActual)==g){ (nuevo->padre)->slink = nodoActual; } } } if (regla == 3) { *regla3 = 1; if(flagString==2){ p2=i-j; //printf("hola\n"); for(k=j+1;k<=i+1;k++){ p1=p2; auxiliar=find_j_i_naive(ST, &p1, k, S2, 1); calculaRegla(auxiliar, p1, k, i, S2); p2--; } } } //printf("chau\n"); // printf(" -- Fin paso3: regla: %d - regla3: %d - nuevo: \n", regla, *regla3); // printTotalString(nuevo); //-----------------PASO 4 -----------------// if (*reglaAnterior == 21 && regla == 21){ (nodoAnterior->padre)->slink = nuevo->padre; } *reglaAnterior = regla; if ((regla == 20) || (regla == 21)){ // printf("\nFin paso4: nodoAnterior: %d\n", (int) nuevo); return nuevo; } else{ // printf("\nFin paso4: nodoAnterior: %d\n", (int) nodoAnterior); return nodoAnterior; } }