19 #ifndef __TPIE_HASH_H__
20 #define __TPIE_HASH_H__
29 extern size_t hash_codes[
sizeof(size_t)][256];
43 size_t m_matrix[
sizeof(size_t)][256];
51 for(
size_t i = 0; i <
sizeof(size_t); ++i) {
53 result ^= hash_bits::hash_codes[i][key & 0xFF];
66 template <
typename T1,
typename T2>
67 struct hash<std::pair<T1,T2> > {
75 inline size_t operator()(
const std::pair<T1,T2> & e)
const {
76 return h1(e.first) + h2(e.second) * 99181;
84 struct hash<const char *> {
91 for(
int i=0; s[i]; i++){
115 template <
typename R,
typename T,
typename ... TT>
116 bool reflect(R & r, T && v, TT && ... vs);
126 void add(
const char * data,
size_t length) {
127 const char * istart = data;
128 const char * iend = data + length;
129 while (iend - istart > stop - cur) {
130 memcpy(cur, istart, stop - cur);
131 istart += stop - cur;
135 memcpy(cur, istart, iend - istart);
136 cur += (iend - istart);
139 template <
typename T>
140 void add(
const T & v) {
141 add(reinterpret_cast<const char *>(&v),
sizeof(v));
155 template <
typename H,
typename T>
156 inline void ghash(H & h,
const T & t);
161 template <
typename H>
164 static constexpr
bool write =
false;
165 static constexpr
bool arithmetic =
true;
166 static constexpr
bool string =
true;
167 static constexpr
bool trivialSerializable =
false;
171 void begin(
const char *) {}
173 void beginArray(
size_t x) {h.add(x);}
175 void name(
const char *) {}
176 void beginStaticArray(
size_t) {}
177 void endStaticArray() {}
179 template <
typename T>
180 bool operator()(
const T & v) {
185 bool operator()(
const std::string & v) {
187 h.add(v.c_str(), v.size());
191 template <
typename T>
192 bool apply(
const T & v) {
203 template <
typename H,
typename T>
204 inline void ghash(H & h,
const T & t) {
211 #endif //__TPIE_HASH_H__
size_t operator()(const char *s) const
Calculate string hash.
size_t operator()(const std::string &s) const
Calculate string hash by using std::string::c_str().
Buffer based hash reflector.
Default tabulation-hashing function for integral (size_t-castable) types.
Default hashing function for C-style strings.
Miscellaneous utility functions.
size_t operator()(const std::pair< T1, T2 > &e) const
Calculate std::pair hash.
size_t operator()(const T &e) const
Calculate integer hash using tabulation hashing.
void ghash(H &h, const T &t)
Hash t using reflection.