GtUword greedyunitedist(GtFrontResource *ftres, const GtSeqabstract *useq, const GtSeqabstract *vseq) { GtUword realdistance, kval; GtWord r; GtFrontspec frontspecspace[2], *fspec, *prevfspec; GtFrontvalue *fptr; #ifdef SKDEBUG printf("unitedistcheckSEPgeneric(ulen=" GT_WU ",vlen=" GT_WU ")\n", ulenvalue,vlenvalue); #endif gt_assert(gt_seqabstract_length(useq) < (GtUword) LONG_MAX); gt_assert(gt_seqabstract_length(vseq) < (GtUword) LONG_MAX); ftres->ulen = (GtWord) gt_seqabstract_length(useq); ftres->vlen = (GtWord) gt_seqabstract_length(vseq); ftres->integermin = -MAX(ftres->ulen,ftres->vlen); prevfspec = &frontspecspace[0]; firstfrontforward(useq,vseq,ftres,prevfspec); if (ftres->ulen == ftres->vlen && GT_FRONT_ROWVALUE(ftres->frontspace) == ftres->vlen) { realdistance = 0; } else { for (kval=1UL, r=1-MIN(ftres->ulen,ftres->vlen); /* Nothing */ ; kval++, r++) { if (prevfspec == &frontspecspace[0]) { fspec = &frontspecspace[1]; } else { fspec = &frontspecspace[0]; } fspec->offset = prevfspec->offset + prevfspec->width; frontspecparms(ftres,fspec,(GtWord) kval,r); while ((GtUword) (fspec->offset + fspec->width) >= ftres->currentallocated) { ftres->currentallocated += kval+1; ftres->frontspace = gt_realloc(ftres->frontspace, sizeof *ftres->frontspace * ftres->currentallocated); } (void) evalfrontforward(useq,vseq,ftres,prevfspec,fspec,r); fptr = ftres->frontspace + fspec->offset - fspec->left; if (accessfront(ftres,fptr,fspec,ftres->vlen - ftres->ulen) == ftres->ulen) { realdistance = kval; break; } if (prevfspec == &frontspecspace[0]) { prevfspec = &frontspecspace[1]; } else { prevfspec = &frontspecspace[0]; } } } #ifdef SKDEBUG printf("unitedistfrontSEP returns "GT_WD"\n",realdistance); #endif return realdistance; }
unsigned long greedyunitedist(const GtUchar *useq, unsigned long ulenvalue, const GtUchar *vseq, unsigned long vlenvalue) { unsigned long currentallocated, realdistance; FrontResource gl; Frontspec frontspecspace[2], *fspec, *prevfspec; Frontvalue *fptr; unsigned long kval; long r; #ifdef SKDEBUG printf("unitedistcheckSEPgeneric(ulen=%lu,vlen=%lu)\n",ulenvalue,vlenvalue); #endif gt_assert(ulenvalue < (unsigned long) LONG_MAX); gt_assert(vlenvalue < (unsigned long) LONG_MAX); currentallocated = 1UL; ALLOCASSIGNSPACE(gl.frontspace,NULL,Frontvalue,currentallocated); gl.useq = useq; gl.vseq = vseq; gl.ubound = useq + ulenvalue; gl.vbound = vseq + vlenvalue; gl.ulen = (long) ulenvalue; gl.vlen = (long) vlenvalue; gl.integermin = -MAX(gl.ulen,gl.vlen); prevfspec = &frontspecspace[0]; firstfrontforward(&gl,prevfspec); if (gl.ulen == gl.vlen && ROWVALUE(&gl.frontspace[0]) == gl.vlen) { realdistance = 0; } else { for (kval=1UL, r=1-MIN(gl.ulen,gl.vlen); /* Nothing */ ; kval++, r++) { if (prevfspec == &frontspecspace[0]) { fspec = &frontspecspace[1]; } else { fspec = &frontspecspace[0]; } fspec->offset = prevfspec->offset + prevfspec->width; frontspecparms(&gl,fspec,(long) kval,r); while ((unsigned long) (fspec->offset + fspec->width) >= currentallocated) { currentallocated += (kval+1); ALLOCASSIGNSPACE(gl.frontspace,gl.frontspace, Frontvalue,currentallocated); } (void) evalfrontforward(&gl,prevfspec,fspec,r); fptr = gl.frontspace + fspec->offset - fspec->left; if (accessfront(&gl,fptr,fspec,gl.vlen - gl.ulen) == gl.ulen) { realdistance = kval; break; } if (prevfspec == &frontspecspace[0]) { prevfspec = &frontspecspace[1]; } else { prevfspec = &frontspecspace[0]; } } } #ifdef SKDEBUG printf("unitedistfrontSEP returns %ld\n",realdistance); #endif FREESPACE(gl.frontspace); return realdistance; }
static void evalentryforward(const GtSeqabstract *useq, const GtSeqabstract *vseq, GtFrontResource *ftres, GtFrontvalue *fval, const GtFrontspec *fspec, GtWord k) { GtWord value, t; GtFrontvalue *fptr; #ifdef SKDEBUG printf("evalentryforward(k="GT_WD")\n",k); #endif fptr = ftres->frontspace + fspec->offset - fspec->left; t = accessfront(ftres,fptr,fspec,k) + 1; /* same diagonal */ #ifdef SKDEBUG printf("same: access(k="GT_WD")="GT_WD"\n",k,t-1); #endif value = accessfront(ftres,fptr,fspec,k-1); /* diagonal below */ #ifdef SKDEBUG printf("below: access(k="GT_WD")="GT_WD"\n",k-1,value); #endif if (t < value) { t = value; } value = accessfront(ftres,fptr,fspec,k+1) + 1; /* diagonal above */ #ifdef SKDEBUG printf("above: access(k="GT_WD")="GT_WD"\n",k+1,value-1); #endif if (t < value) { t = value; } #ifdef SKDEBUG printf("maximum: t="GT_WD"\n",t); /* the maximum over three values */ #endif if (t < 0 || t+k < 0) /* no negative value */ { GT_FRONT_STORE(ftres,GT_FRONT_ROWVALUE(fval),GT_FRONT_MINUSINFINITY(ftres)); } else { if (ftres->ulen != 0 && ftres->vlen != 0 && t < ftres->ulen && t + k < ftres->vlen) { GtUword lcp, minlen = (GtUword) MIN(ftres->ulen - t,ftres->vlen - (t + k)); lcp = gt_seqabstract_lcp(true, useq, vseq, (GtUword) t, (GtUword) (t + k), minlen); t += lcp; } if (t > ftres->ulen || t + k > ftres->vlen) { GT_FRONT_STORE(ftres,GT_FRONT_ROWVALUE(fval), GT_FRONT_MINUSINFINITY(ftres)); } else { GT_FRONT_STORE(ftres,GT_FRONT_ROWVALUE(fval),t); } } }
static void evalentryforward(FrontResource *gl, Frontvalue *fval, const Frontspec *fspec, long k) { long value, t; const GtUchar *uptr, *vptr; GtUchar a, b; Frontvalue *fptr; #ifdef SKDEBUG printf("evalentryforward(k=%ld)\n",k); #endif fptr = gl->frontspace + fspec->offset - fspec->left; t = accessfront(gl,fptr,fspec,k) + 1; /* same diagonal */ #ifdef SKDEBUG printf("same: access(k=%ld)=%ld\n",k,t-1); #endif value = accessfront(gl,fptr,fspec,k-1); /* diagonal below */ #ifdef SKDEBUG printf("below: access(k=%ld)=%ld\n",k-1,value); #endif if (t < value) { t = value; } value = accessfront(gl,fptr,fspec,k+1) + 1; /* diagonal above */ #ifdef SKDEBUG printf("above: access(k=%ld)=%ld\n",k+1,value-1); #endif if (t < value) { t = value; } #ifdef SKDEBUG printf("maximum: t=%ld\n",t); /* the maximum over three values */ #endif if (t < 0 || t+k < 0) /* no negative value */ { STOREFRONT(gl,ROWVALUE(fval),MINUSINFINITYFRONT(gl)); } else { uptr = gl->useq + t; vptr = gl->vseq + t + k; if (gl->ulen != 0 && gl->vlen != 0) /* only for nonempty strings */ { if (uptr == vptr) /* strings are equal */ { t = gl->ulen-1; } else { for (/* Nothing */; uptr < gl->ubound && vptr < gl->vbound; uptr++, vptr++) { a = *uptr; b = *vptr; COMPARESYMBOLS(a,b); } t = (long) (uptr - gl->useq); } } if (gl->useq + t > gl->ubound || gl->vseq + t + k > gl->vbound) { STOREFRONT(gl,ROWVALUE(fval),MINUSINFINITYFRONT(gl)); } else { STOREFRONT(gl,ROWVALUE(fval),t); } } }