forked from voutcn/megahit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hash.h
99 lines (83 loc) · 2.7 KB
/
hash.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
/*
* MEGAHIT
* Copyright (C) 2014 The University of Hong Kong
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file hash.h
* @brief Hash Functionals.
* @author Yu Peng ([email protected])
* @version 1.0.0
* @date 2011-08-24
*/
#ifndef __BASIC_HASH_H_
#define __BASIC_HASH_H_
#include <stdint.h>
#include <functional>
template <typename T>
struct Hash: public std::unary_function<T, uint64_t>
{
uint64_t operator ()(const T &value) const
{ return value.hash(); }
};
template <>
struct Hash<int8_t>: public std::unary_function<int8_t, uint64_t>
{
uint64_t operator ()(int8_t value) const
{ return (uint64_t(value)* 1299709 + 104729) % 323780508946331ULL; }
};
template <>
struct Hash<uint8_t>: public std::unary_function<uint8_t, uint64_t>
{
uint64_t operator ()(uint8_t value) const
{ return (uint64_t(value)* 1299709 + 104729) % 323780508946331ULL; }
};
template <>
struct Hash<int16_t>: public std::unary_function<int16_t, uint64_t>
{
uint64_t operator ()(int16_t value) const
{ return (uint64_t(value)* 1299709 + 104729) % 323780508946331ULL; }
};
template <>
struct Hash<uint16_t>: public std::unary_function<uint16_t, uint64_t>
{
uint64_t operator ()(uint16_t value) const
{ return (uint64_t(value)* 1299709 + 104729) % 323780508946331ULL; }
};
template <>
struct Hash<int32_t>: public std::unary_function<int32_t, uint64_t>
{
uint64_t operator ()(int32_t value) const
{ return (uint64_t(value)* 1299709 + 104729) % 323780508946331ULL; }
};
template <>
struct Hash<uint32_t>: public std::unary_function<uint32_t, uint64_t>
{
uint64_t operator ()(uint32_t value) const
{ return (uint64_t(value)* 1299709 + 104729) % 323780508946331ULL; }
};
template <>
struct Hash<int64_t>: public std::unary_function<int64_t, uint64_t>
{
uint64_t operator ()(int64_t value) const
{ return (uint64_t(value)* 1299709 + 104729) % 323780508946331ULL; }
};
template <>
struct Hash<uint64_t>: public std::unary_function<uint64_t, uint64_t>
{
uint64_t operator ()(uint64_t value) const
{ return (uint64_t(value)* 1299709 + 104729) % 323780508946331ULL; }
};
#endif