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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
#include <seqan/basic.h>
#include <seqan/sequence.h>
using namespace seqan;
//![hashAll]
template <typename TShape, typename TString>
void hashAll(TShape & shape, TString & str)
{
typedef typename Iterator<TString>::Type TIterator;
TIterator it = begin(str);
TIterator it_end = end(str) - span(shape);
while (it != it_end)
{
unsigned int hash_value = hash(shape, it);
/* do some things with the hash value */ ++it;
//![hashAll]
ignoreUnusedVariableWarning(hash_value);
//![hashAll]
}
}
//![hashAll]
//![classShape]
struct SimpleShape_;
typedef Tag<SimpleShape_> SimpleShape;
template <typename TValue, typename TSpec = SimpleShape>
class Shape;
//![classShape]
//![classSimpleShape]
template <typename TValue>
class Shape< TValue, SimpleShape >
{
public:
unsigned int span;
};
//![classSimpleShape]
//![classUngappedShape]
template <unsigned int q = 0>
struct UngappedShape;
template <typename TValue, unsigned int q>
class Shape< TValue, UngappedShape<q> >
{
public:
static unsigned int const span = q;
};
//![classUngappedShape]
//![hashNext]
template <typename TValue, unsigned int q, typename TIterator>
inline unsigned int
hashNext(Shape< TValue, UngappedShape<q> > const & shape, TIterator it, unsigned int prev)
{
unsigned int val = prev * ValueSize<TValue>::VALUE - *it * shape.fac
+ *(it + shape.span);
return val;
// shape.fac stores |Σ|^q
}
//![hashNext]
//![specializedHashAll]
template <typename TValue, unsigned int q, typename TString>
void specializedHashAll(Shape< TValue, UngappedShape<q> > & shape, TString & str)
{
typedef typename Iterator<TString>::Type TIterator;
TIterator it = begin(str);
TIterator it_end = end(str) - span(shape);
unsigned int hash_value = hash(shape, it);
/* do some things with the hash value */
//![specializedHashAll]
ignoreUnusedVariableWarning(hash_value);
//![specializedHashAll]
while (++it != it_end)
{
unsigned int hash_value = hashNext(shape, it, hash_value);
/* do some things with the hash value */
}
}
//![specializedHashAll]
int main()
{
return 0;
}
|