Compute a hash-like value of the packed sequence over the first 16 * bases and the reverse complement of the last 16 bases * The reverse complement of the last 16 bases is used so that a * sequence and its reverse complement will hash to the same value. * @todo make this faster */
| 44 | * @todo make this faster |
| 45 | */ |
| 46 | unsigned Kmer::getCode() const |
| 47 | { |
| 48 | /* At k=19, this hash function always returns an even number due |
| 49 | * to the sequence and its reverse complement overlapping when the |
| 50 | * xor is calculated. A more general solution is needed. */ |
| 51 | const unsigned NUM_BYTES |
| 52 | = s_length < 8 ? 1 |
| 53 | : s_length < 20 ? s_length/8 |
| 54 | : 4; |
| 55 | Kmer rc = *this; |
| 56 | rc.reverseComplement(); |
| 57 | |
| 58 | const unsigned prime = 101; |
| 59 | unsigned sum = 0; |
| 60 | for (unsigned i = 0; i < NUM_BYTES; i++) |
| 61 | sum = prime * sum + (m_seq[i] ^ rc.m_seq[i]); |
| 62 | return sum; |
| 63 | } |
| 64 | |
| 65 | size_t Kmer::getHashCode() const |
| 66 | { |
nothing calls this directly
no test coverage detected