File: DiagonalTable.cc

package info (click to toggle)
last-align 963-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,380 kB
  • sloc: cpp: 41,136; python: 2,744; ansic: 1,240; makefile: 383; sh: 255
file content (34 lines) | stat: -rw-r--r-- 857 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright 2008 Martin C. Frith

#include "DiagonalTable.hh"

namespace cbrc{

bool DiagonalTable::isCovered( indexT sequentialPos, indexT randomPos ){

  indexT diagonal = sequentialPos - randomPos;  // wrap-around is OK
  indexT bin = diagonal % BINS;
  std::vector<pairT>& v = hits[bin];

  for( std::vector<pairT>::iterator i = v.begin(); i < v.end(); /* noop */ ){
    if( i->first >= sequentialPos ){
      if( i->second == diagonal ) return true;
      ++i;
    }else{
      i = v.erase(i);  // hopefully we rarely get here
    }
  }

  return false;
}

void DiagonalTable::addEndpoint( indexT sequentialPos, indexT randomPos ){

  indexT diagonal = sequentialPos - randomPos;  // wrap-around is OK
  indexT bin = diagonal % BINS;
  std::vector<pairT>& v = hits[bin];

  v.push_back( pairT( sequentialPos, diagonal ) );
}

}  // end namespace cbrc