void checksuflinks(Suffixarray *s, Uint i, Uint j){ Uint k, childlcp, suflcp, *space = NULL; PairUint* child, childsuf; Container *children; // ignore singletons as initial input if (i == j){ return; } children = getChildintervals(space, s, i, j, 0); for (k = 0; k < bl_containerSize(children); k++){ child = (PairUint *) bl_containerGet(children, k); // exclude singletons if (child->a == child->b){ return; } // check suflink of child childlcp = getlcpval(s, child->a, child->b); childsuf = getSuflink(s, child->a, child->b); suflcp = getlcpval(s, childsuf.a, childsuf.b); if (childlcp != suflcp + 1){ DBG("suf[%u, %u, %u]=[%u, %u, %u]\n", child->a, child->b, childlcp, childsuf.a, childsuf.b, suflcp); } // recursively check all children of child checksuflinks(s, child->a, child->b); } bl_containerDestruct(children, NULL); free(children); }
PairUint getCharInterval(void *space, Suffixarray *s, Uint i, Uint j, Uint pos, char ch) { List *list; Uint lcp=0; PairUint lr; lr.a = 1; lr.b = 0; if(i==j) return lr; list = getChildintervals(space, s, i, j); lcp = getlcpval(s, i, j); for(i=0; i < list->length; i++) { if(s->suffixptr[s->suftab[((PairUint*)list->nodes[i].data)->a]][lcp] == ch) { lr.a = ((PairUint*)list->nodes[i].data)->a; lr.b = ((PairUint*)list->nodes[i].data)->b; break; } } wrapList(space, list, destructinterval); return lr; }
void constructsuflinks(void *space, Suffixarray *s) { Uint i, j, a, b, k, nooflists, lcp, pos; Stack istack; Stack jstack; List *children, **lists; PairUint **data, slinkinterval; nooflists = maxlcp(s) +1; lists = ALLOCMEMORY(space, NULL, List*, nooflists); memset(lists, 0, sizeof(List*)*nooflists); initStack(space, &istack, 1000); initStack(space, &jstack, 1000); stackpush(space, &istack, 0); stackpush(space, &jstack, s->numofsuffixes-1); while(!stackisempty(&istack)) { i = stackpop(&istack); j = stackpop(&jstack); lcp = getlcpval(s, i, j); /*printf("adding list %d\n", lcp);*/ if (lists[lcp] == NULL) { lists[lcp] = initList(space, 10); } addinterval(space, lists[lcp], i, j); /*printf("lcp: %d-[%d,%d]\n", lcp, i, j);*/ children = getChildintervals(space, s, i, j); data = (PairUint**) dataList(space, children); for(k=children->length; k > 0; k--) { a = data[k-1]->a; b = data[k-1]->b; FREEMEMORY(space, data[k-1]); if(a != b) { stackpush(space, &istack, a); stackpush(space, &jstack, b); } } FREEMEMORY(space, data); wrapList(space, children, NULL); } destructStack(space, &istack); destructStack(space, &jstack); s->suflink_l = ALLOCMEMORY(space, NULL, Uint, s->numofsuffixes); s->suflink_r = ALLOCMEMORY(space, NULL, Uint, s->numofsuffixes); memset(s->suflink_l, 0, sizeof(Uint)*s->numofsuffixes); memset(s->suflink_r, 0, sizeof(Uint)*s->numofsuffixes); for(i=1; i < nooflists; i++) { if(lists[i] != NULL && lists[i-1] !=NULL) { for(j=0; j < lists[i]->length; j++) { /*printf("looking at interval [%d,%d], list %d\n", ((PairUint*)lists[i]->nodes[j].data)->a, ((PairUint*)lists[i]->nodes[j].data)->b, i);*/ slinkinterval = findslinkinterval(space, s, lists, i, j); pos = getfirstlindex(s, ((PairUint*)lists[i]->nodes[j].data)->a, ((PairUint*)lists[i]->nodes[j].data)->b); /*printf("store at %d: [%d,%d]\n", pos, slinkinterval.a, slinkinterval.b);*/ s->suflink_l[pos]=slinkinterval.a; s->suflink_r[pos]=slinkinterval.b; } } wrapList(space, lists[i-1], destructinterval); } FREEMEMORY(space, lists); return; }