forked from mourisl/Rcorrector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Store.h
89 lines (76 loc) · 1.45 KB
/
Store.h
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
#ifndef _MOURISL_CLASS_STORE
#define _MOURISL_CLASS_STORE
/**
The wrapper for kmers' storage.
*/
#include <stdio.h>
#include <stdint.h>
#if __cplusplus<=199711L
#include <tr1/unordered_map>
#else
#include <unordered_map>
#endif
#include "KmerCode.h"
class Store
{
private:
uint64_t size ;
//std::map<uint64_t, int> hash ;
#if __cplusplus<=199711L
std::tr1::unordered_map<uint64_t, int> hash ;
#else
std::unordered_map<uint64_t, int> hash ;
#endif
public:
Store()
{
}
Store( uint64_t cnt )
{
#if __cplusplus>199711L
hash.reserve( cnt ) ;
#endif
}
~Store()
{
}
void Allocate( uint64_t cnt )
{
#if __cplusplus>199711L
hash.reserve( cnt ) ;
#endif
}
int Put( KmerCode &code, int cnt )
{
if ( !code.IsValid() )
return 0 ;
hash[ code.GetCanonicalKmerCode() ] = cnt ;
return 0 ;
}
int GetCount( KmerCode &code )
{
if ( !code.IsValid() )
return 0 ;
if ( hash.count( code.GetCanonicalKmerCode() ) == 0 )
return 0 ;
return hash[ code.GetCanonicalKmerCode() ] ;
}
uint64_t GetCanonicalKmerCode( uint64_t code, int k )
{
int i ;
uint64_t crCode = 0ull ; // complementary code
for ( i = 0 ; i < k ; ++i )
{
//uint64_t tmp = ( code >> ( 2ull * (k - i - 1) ) ) & 3ull ;
//crCode = ( crCode << 2ull ) | ( 3 - tmp ) ;
uint64_t tmp = ( code >> ( 2ull * i ) ) & 3ull ;
crCode = ( crCode << 2ull ) | ( 3ull - tmp ) ;
}
return crCode < code ? crCode : code ;
}
int Clear()
{
return 0 ;
}
} ;
#endif