File: default_hasher.hh

package info (click to toggle)
salmon 0.7.2%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,352 kB
  • ctags: 5,243
  • sloc: cpp: 42,341; ansic: 6,252; python: 228; makefile: 207; sh: 190
file content (29 lines) | stat: -rw-r--r-- 816 bytes parent folder | download
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
#ifndef _DEFAULT_HASHER_HH
#define _DEFAULT_HASHER_HH

#include <string>
#include <type_traits>

/*! DefaultHasher is the default hash class used in the table. It overloads a
 *  few types that std::hash does badly on (namely integers), and falls back to
 *  std::hash for anything else. */
template <class Key>
class DefaultHasher {
    std::hash<Key> fallback;

public:
    template <class T = Key>
    typename std::enable_if<std::is_integral<T>::value, size_t>::type
    operator()(const Key& k) const {
        // This constant is found in the CityHash code
        return k * 0x9ddfea08eb382d69ULL;
    }

    template <class T = Key>
    typename std::enable_if<!std::is_integral<T>::value, size_t>::type
    operator()(const Key& k) const {
        return fallback(k);
    }
};

#endif // _DEFAULT_HASHER_HH