forked from jfmrod/MAPseq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ekmerhashmap_dec.h
114 lines (85 loc) · 2.79 KB
/
ekmerhashmap_dec.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#ifndef EKMERHASHMAP_DEC_H
#define EKMERHASHMAP_DEC_H
#include <eutils/ehashfunc.h>
inline size_t hash_lookup3_cstr(const char* cstr,int len)
{
#ifdef __i386__
return(hash_lookup3(cstr,len,0x75483842));
#else // __X86_64__
return(hash_lookup3_64(cstr,len,0x75483842,0xB5749368));
#endif
}
template <int KSIZE,class T>
class ekmerhashitem
{
public:
size_t hash;
const char *key;
T *value;
ekmerhashitem<KSIZE,T>* next;
ekmerhashitem<KSIZE,T>* prev;
ekmerhashitem(const char *key,T* value,ekmerhashitem<KSIZE,T>* next,size_t hash);
~ekmerhashitem();
};
template <int KSIZE,class T>
ekmerhashitem<KSIZE,T>::ekmerhashitem(const char *_key,T* _value,ekmerhashitem<KSIZE,T>* _next,size_t _hash): key(_key),value(_value),next(_next),prev(0x00),hash(_hash)
{
// memcpy(key,_key,KSIZE);
if (next)
next->prev=this;
}
template <int KSIZE,class T>
ekmerhashitem<KSIZE,T>::~ekmerhashitem()
{
}
template <int KSIZE,class T,size_t (*hashfunc)(const char*,int)=hash_lookup3_cstr>
class ekmerhashmap
{
mutable ekmerhashitem<KSIZE,T> **_hashitems;
size_t count;
public:
mutable size_t _hashmask;
ekmerhashmap();
ekmerhashmap(const ekmerhashmap<KSIZE,T,hashfunc>& oldhm);
~ekmerhashmap();
inline size_t size() const { return(count); }
T& add(const char *key,const T& value);
T& addref(const char *key,T* value);
inline const T& operator[](const char *key) const;
T& operator[](const char *key);
ekmerhashmap<KSIZE,T,hashfunc>& operator+=(const ekmerhashmap<KSIZE,T,hashfunc>& hm);
T& values(const char *key);
const T& values(const char *key) const;
bool exists(const char *key) const ;
long findkey(const char *key,size_t pos=0) const;
void clear();
void resizehash(size_t i=0) const;
void reserve(size_t i);
void erase(const char *key);
ekmerhashitem<KSIZE,T>* gethashitem(size_t khash,const char *key) const;
inline size_t hash(const char *key) const { return(hashfunc(key,KSIZE)); }
class iter
{
public:
const ekmerhashmap<KSIZE,T,hashfunc> *hashmap;
ekmerhashitem<KSIZE,T> *hitem;
size_t bucket;
iter();
iter& operator++();
size_t hash() const;
const char *key() const;
T& value() const;
T& operator*() const;
T* operator->() const;
bool operator==(const iter& i) const;
bool operator!=(const iter& i) const;
iter& operator=(const iter& i);
};
void erase(const typename ekmerhashmap<KSIZE,T,hashfunc>::iter&);
typename ekmerhashmap<KSIZE,T,hashfunc>::iter get(const char *key) const;
typename ekmerhashmap<KSIZE,T,hashfunc>::iter gethash(size_t hash,const char *key) const;
typename ekmerhashmap<KSIZE,T,hashfunc>::iter addhash(size_t hash,const char *key,const T&);
typename ekmerhashmap<KSIZE,T,hashfunc>::iter begin() const;
typename ekmerhashmap<KSIZE,T,hashfunc>::iter end() const;
};
#endif