Suffixarray* constructSufArr(void *space, IntSequence **s, Uint len, FAlphabet* alphabet) { Uint i, numofsuffixes, *sorted, *inv_suftab, **suffixptr; MultiIntSeq *mseq; Suffixarray *arr; mseq = concatIntSequences(space, s, len, 4000, 4001); numofsuffixes = (mseq->totallength - mseq->numofsequences)+1; inv_suftab = ALLOCMEMORY(space, NULL, Uint , numofsuffixes); arr = ALLOCMEMORY(space, NULL, Suffixarray, 1); suffixptr = getSuffixPtr(space, mseq, 4000, 4001); sorted = quickSortMultikey (space, suffixptr, numofsuffixes, cmpIntSequence, numofsuffixes-1, NULL); for (i=0; i < numofsuffixes; i++) { inv_suftab[sorted[i]]=i; } arr->seq = mseq; arr->numofsuffixes = numofsuffixes; arr->suffixptr = suffixptr; arr->suftab = sorted; arr->inv_suftab = inv_suftab; return arr; }
Suffixarray* constructSufArr(void *space, CharSequence **s, Uint len, FAlphabet* alphabet) { Uint i, numofsuffixes, *sorted, *inv_suftab; char **suffixptr; MultiCharSeq *mseq; Suffixarray *arr; mseq = concatCharSequences(space, s, len, (char)254, (char)127); numofsuffixes = (mseq->totallength - mseq->numofsequences)+1; printf("allocating space for %d suffixes (%d bytes)\n", numofsuffixes, 2*numofsuffixes*sizeof(Uint)); inv_suftab = ALLOCMEMORY(space, NULL, Uint , numofsuffixes); arr = ALLOCMEMORY(space, NULL, Suffixarray, 1); printf("constructing suftab.\n"); suffixptr = getSuffixPtr(space, mseq, (char)254, (char)127); sorted = quickSortMultikey (space, suffixptr, numofsuffixes, cmpCharSequence, numofsuffixes-1, NULL); printf("constructing inv_suftab.\n"); for (i=0; i < numofsuffixes; i++) { inv_suftab[sorted[i]]=i; } arr->seq = mseq; arr->numofsuffixes = numofsuffixes; arr->suffixptr = suffixptr; arr->suftab = sorted; arr->inv_suftab = inv_suftab; return arr; }
Suffixarray* constructSufArr(void *space, CharSequence **s, Uint len, FAlphabet* alphabet, unsigned char silent) { Uint i, numofsuffixes, *sorted, *inv_suftab; MultiCharSeq *mseq; Suffixarray *arr; unsigned char *temp, *mdfive=NULL; mseq = concatCharSequences(space, s, len, (char)126, (char)127); numofsuffixes = mseq->totallength; mdfive = ALLOCMEMORY(space, NULL, char, 16); temp = MD5R((unsigned char*)mseq->sequences, numofsuffixes, NULL); memmove(mdfive, temp, 16); if(!silent) NFO("alphabet of size (%d): %s\n", mseq->mapsize, mseq->map); if(!silent) NFO("size of db sequence: %u\n", numofsuffixes); inv_suftab = ALLOCMEMORY(space, NULL, Uint , numofsuffixes); arr = ALLOCMEMORY(space, NULL, Suffixarray, 1); if(!silent) MSG("constructing suftab.\n"); #ifdef SUF_MKQUICKSORT sorted = quickSortMultikey (space, mseq->sequences, numofsuffixes, cmpCharSequence, numofsuffixes-1, NULL); #else sorted = alurusort(space, mseq->sequences, &(numofsuffixes)); #endif if (!silent)NFO("constructing inv_suftab (%u).\n", numofsuffixes); for (i=0; i < numofsuffixes; i++) { if (sorted[i] > numofsuffixes) fprintf(stderr, "construction error? %u: %u\n",i, sorted[i]); inv_suftab[sorted[i]]=i; } if (!silent)MSG("inv_suftab constructed.\n"); arr->seq = mseq; arr->numofsuffixes = numofsuffixes; arr->suftab = sorted; arr->inv_suftab = inv_suftab; arr->mdfive = mdfive; arr->lcpctab = NULL; arr->llvtab = NULL; arr->id = NULL; arr->idvtab = NULL; arr->chldtab = NULL; arr->bcktab = NULL; arr->suflink = NULL; arr->suflink_l = NULL; arr->suflink_r = NULL; arr->llint = 1; return arr; }