Refactor
authorMartin C. Frith
Tue Oct 08 17:19:10 2019 +0900 (6 weeks ago)
changeset 9904011a21f96ad
parent 989 50bcc51ca59b
child 991 7f841cc97f20
Refactor
src/SubsetMinimizerFinder.cc
src/SubsetMinimizerFinder.hh
src/SubsetSuffixArray.cc
src/lastal.cc
     1.1 --- a/src/SubsetMinimizerFinder.cc	Mon Oct 07 20:30:57 2019 +0900
     1.2 +++ b/src/SubsetMinimizerFinder.cc	Tue Oct 08 17:19:10 2019 +0900
     1.3 @@ -6,38 +6,33 @@
     1.4  namespace cbrc {
     1.5  
     1.6  void SubsetMinimizerFinder::init(const CyclicSubsetSeed &seed,
     1.7 -				 const uchar *text,
     1.8 -				 size_t beg,
     1.9 -				 size_t end) {
    1.10 +				 const uchar *beg,
    1.11 +				 const uchar *end) {
    1.12    const uchar *m = seed.firstMap();
    1.13 -  while (beg < end && m[text[beg]] == CyclicSubsetSeed::DELIMITER) ++beg;
    1.14 +  while (beg < end && m[*beg] == CyclicSubsetSeed::DELIMITER) ++beg;
    1.15    minima.assign(1, beg);
    1.16  }
    1.17  
    1.18  bool SubsetMinimizerFinder::isMinimizer(const CyclicSubsetSeed &seed,
    1.19 -					const uchar *text,
    1.20 -					size_t pos,
    1.21 -					size_t end,
    1.22 +					const uchar *pos,
    1.23 +					const uchar *end,
    1.24  					size_t window) {
    1.25    const uchar *subsetMap = seed.firstMap();
    1.26  
    1.27    while (true) {
    1.28 -    size_t currentMinimum = minima[0];
    1.29 +    const uchar *currentMinimum = minima[0];
    1.30      if (currentMinimum > pos) return false;
    1.31      if (currentMinimum == pos) return true;
    1.32 -    size_t newPos = minima.back() + 1;
    1.33 +    const uchar *newPos = minima.back() + 1;
    1.34      if (newPos == end) return false;
    1.35 -    const uchar *newText = text + newPos;
    1.36 -    if (subsetMap[*newText] == CyclicSubsetSeed::DELIMITER) {
    1.37 -      init(seed, text, newPos + 1, end);
    1.38 +    if (subsetMap[*newPos] == CyclicSubsetSeed::DELIMITER) {
    1.39 +      init(seed, newPos + 1, end);
    1.40        continue;
    1.41      }
    1.42 -    size_t stop = (newPos - currentMinimum >= window);
    1.43 +    size_t diff = newPos - currentMinimum;
    1.44 +    size_t stop = (diff >= window);
    1.45      size_t i = minima.size();
    1.46 -    while (i > stop) {
    1.47 -      size_t oldPos = minima[i - 1];
    1.48 -      const uchar *oldText = text + oldPos;
    1.49 -      if (!seed.isLess(newText, oldText, subsetMap)) break;
    1.50 +    while (i > stop && seed.isLess(newPos, minima[i - 1], subsetMap)) {
    1.51        --i;
    1.52      }
    1.53      minima.resize(i);
     2.1 --- a/src/SubsetMinimizerFinder.hh	Mon Oct 07 20:30:57 2019 +0900
     2.2 +++ b/src/SubsetMinimizerFinder.hh	Tue Oct 08 17:19:10 2019 +0900
     2.3 @@ -33,18 +33,16 @@
     2.4  class SubsetMinimizerFinder {
     2.5  public:
     2.6    void init(const CyclicSubsetSeed &seed,
     2.7 -	    const uchar *text,
     2.8 -	    size_t beg,
     2.9 -	    size_t end);
    2.10 +	    const uchar *beg,
    2.11 +	    const uchar *end);
    2.12  
    2.13     bool isMinimizer(const CyclicSubsetSeed &seed,
    2.14 -		    const uchar *text,
    2.15 -		    size_t pos,
    2.16 -		    size_t end,
    2.17 +		    const uchar *pos,
    2.18 +		    const uchar *end,
    2.19  		    size_t window);
    2.20  
    2.21  private:
    2.22 -  std::vector<size_t> minima;
    2.23 +  std::vector<const uchar *> minima;
    2.24  };
    2.25  
    2.26  }
     3.1 --- a/src/SubsetSuffixArray.cc	Mon Oct 07 20:30:57 2019 +0900
     3.2 +++ b/src/SubsetSuffixArray.cc	Tue Oct 08 17:19:10 2019 +0900
     3.3 @@ -15,11 +15,11 @@
     3.4    assert(step > 0);
     3.5    const uchar *subsetMap = seed.firstMap();
     3.6    SubsetMinimizerFinder f;
     3.7 -  f.init(seed, text, beg, end);
     3.8 +  f.init(seed, text + beg, text + end);
     3.9  
    3.10    while (true) {
    3.11      if (minimizerWindow > 1) {
    3.12 -      if (f.isMinimizer(seed, text, beg, end, minimizerWindow))
    3.13 +      if (f.isMinimizer(seed, text + beg, text + end, minimizerWindow))
    3.14  	suffixArray.v.push_back(beg);
    3.15      } else {
    3.16        if (subsetMap[text[beg]] < CyclicSubsetSeed::DELIMITER)
     4.1 --- a/src/lastal.cc	Mon Oct 07 20:30:57 2019 +0900
     4.2 +++ b/src/lastal.cc	Tue Oct 08 17:19:10 2019 +0900
     4.3 @@ -529,15 +529,16 @@
     4.4  
     4.5    std::vector< SubsetMinimizerFinder > minFinders( numOfIndexes );
     4.6    for( unsigned x = 0; x < numOfIndexes; ++x ){
     4.7 -    minFinders[x].init( suffixArrays[x].getSeed(), dis.b, loopBeg, loopEnd );
     4.8 +    minFinders[x].init(suffixArrays[x].getSeed(),
     4.9 +		       dis.b + loopBeg, dis.b + loopEnd);
    4.10    }
    4.11  
    4.12    for( indexT i = loopBeg; i < loopEnd; i += args.queryStep ){
    4.13      for( unsigned x = 0; x < numOfIndexes; ++x ){
    4.14        const SubsetSuffixArray& sax = suffixArrays[x];
    4.15 -      if( args.minimizerWindow > 1 &&
    4.16 -	  !minFinders[x].isMinimizer( sax.getSeed(), dis.b, i, loopEnd,
    4.17 -				      args.minimizerWindow ) ) continue;
    4.18 +      if (args.minimizerWindow > 1 &&
    4.19 +	  !minFinders[x].isMinimizer(sax.getSeed(), dis.b + i, dis.b + loopEnd,
    4.20 +				     args.minimizerWindow)) continue;
    4.21        const indexT* beg;
    4.22        const indexT* end;
    4.23        sax.match( beg, end, dis.b + i, dis.a,