File: HashedTupleListImpl.hpp

package info (click to toggle)
pbseqlib 5.3.1%2Bdfsg-2.1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,136 kB
  • sloc: cpp: 77,246; python: 570; makefile: 312; sh: 111; ansic: 9
file content (135 lines) | stat: -rw-r--r-- 3,254 bytes parent folder | download | duplicates (4)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#ifndef _BLASR_HASHED_TUPLE_LIST_IMPL_HPP_
#define _BLASR_HASHED_TUPLE_LIST_IMPL_HPP_

template <typename T_Tuple>
HashedTupleList<T_Tuple>::HashedTupleList()
{
    Initialize(5);
}

template <typename T_Tuple>
HashedTupleList<T_Tuple>::HashedTupleList(int _hashLength)
{
    Initialize(_hashLength);
    std::cout << hashTable.size() << std::endl;
}

template <typename T_Tuple>
void HashedTupleList<T_Tuple>::Initialize(int _hashLength)
{
    mask = 0;
    int i;
    hashLength = _hashLength;
    hashTable.resize(1L << (hashLength * 2));
    hashTableLength = hashTable.size();

    for (i = 0; i < hashLength; i++) {
        mask = mask << 2L;
        mask = mask + 3L;
    }
}

template <typename T_Tuple>
void HashedTupleList<T_Tuple>::clear()
{
    // Synonym.
    Clear();
}

template <typename T_Tuple>
void HashedTupleList<T_Tuple>::Clear()
{
    int i;
    for (i = 0; i < hashTableLength; i++) {
        hashTable[i].tupleList.clear();
    }
}

template <typename T_Tuple>
void HashedTupleList<T_Tuple>::Sort()
{
    int i;
    for (i = 0; i < hashTableLength; i++) {
        sort(hashTable[i].tupleList.begin(), hashTable[i].tupleList.end());
    }
}

template <typename T_Tuple>
void HashedTupleList<T_Tuple>::Append(T_Tuple tuple)
{
    int hashValue = tuple.tuple & mask;
    std::cout << "htl adding " << tuple.tuple << std::endl;
    hashTable[hashValue].tupleList.push_back(tuple);
}

template <typename T_Tuple>
void HashedTupleList<T_Tuple>::Insert(T_Tuple tuple)
{
    std::cout << "htl adding " << tuple.tuple << std::endl;
    int hashValue = tuple.tuple & mask;
    hashTable[hashValue].Insert(tuple);
}

template <typename T_Tuple>
int HashedTupleList<T_Tuple>::Find(T_Tuple tuple)
{
    int hashValue, index;
    return Find(tuple, hashValue, index);
}

template <typename T_Tuple>
void HashedTupleList<T_Tuple>::Print()
{
    int i;
    for (i = 0; i < hashTableLength; i++) {
        hashTable[i].Print();
    }
}

//
// Provide a version of find that stores easy access to
// the original tuple.
//
template <typename T_Tuple>
int HashedTupleList<T_Tuple>::Find(T_Tuple tuple, int &hashValue, int &index)
{
    hashValue = tuple.tuple & mask;
    if (hashTable[hashValue].size()) {
        return ((index = hashTable[hashValue].Find(tuple)) != -1);
    } else {
        return 0;
    }
}

template <typename T_Tuple>
void HashedTupleList<T_Tuple>::FindAll(T_Tuple &tuple,
                                       typename std::vector<T_Tuple>::const_iterator &firstPos,
                                       typename std::vector<T_Tuple>::const_iterator &endPos)
{
    int hashValue;
    hashValue = tuple.tuple & mask;
    hashTable[hashValue].FindAll(tuple, firstPos, endPos);
}

template <typename T_Tuple>
int HashedTupleList<T_Tuple>::GetHashLength()
{
    return hashLength;
}

template <typename T_Tuple>
void SequenceToHash(DNASequence &seq, HashedTupleList<T_Tuple> &hash, TupleMetrics &tm)
{

    int i;
    T_Tuple tuple;
    int res = 0;
    for (i = 0; i < seq.length - hash.hashLength + 1; i++) {
        if ((res and (res = tuple.ShiftAddRL(seq.seq[i + tm.tupleSize - 1], tm))) or
            (!res and (res = tuple.FromStringRL(&seq.seq[i], tm)))) {
            hash.Insert(tuple);
        }
    }
}

#endif