File: example_hashing.cpp

package info (click to toggle)
seqan2 2.4.0%2Bdfsg-16
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 224,180 kB
  • sloc: cpp: 256,886; ansic: 91,672; python: 8,330; sh: 995; xml: 570; makefile: 252; awk: 51; javascript: 21
file content (89 lines) | stat: -rw-r--r-- 2,187 bytes parent folder | download | duplicates (7)
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;
}