]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. |
11fdf7f2 TL |
2 | // This source code is licensed under both the GPLv2 (found in the |
3 | // COPYING file in the root directory) and Apache 2.0 License | |
4 | // (found in the LICENSE.Apache file in the root directory). | |
7c673cae FG |
5 | // |
6 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. | |
7 | // Use of this source code is governed by a BSD-style license that can be | |
8 | // found in the LICENSE file. See the AUTHORS file for names of contributors. | |
9 | // | |
10 | // Simple hash function used for internal data structures | |
11 | ||
12 | #pragma once | |
13 | #include <stddef.h> | |
14 | #include <stdint.h> | |
15 | ||
16 | #include "rocksdb/slice.h" | |
494da23a | 17 | #include "util/murmurhash.h" |
7c673cae FG |
18 | |
19 | namespace rocksdb { | |
20 | ||
494da23a TL |
21 | // Non-persistent hash. Only used for in-memory data structure |
22 | // The hash results are applicable to change. | |
23 | extern uint64_t NPHash64(const char* data, size_t n, uint32_t seed); | |
24 | ||
7c673cae FG |
25 | extern uint32_t Hash(const char* data, size_t n, uint32_t seed); |
26 | ||
27 | inline uint32_t BloomHash(const Slice& key) { | |
28 | return Hash(key.data(), key.size(), 0xbc9f1d34); | |
29 | } | |
30 | ||
494da23a TL |
31 | inline uint64_t GetSliceNPHash64(const Slice& s) { |
32 | return NPHash64(s.data(), s.size(), 0); | |
33 | } | |
34 | ||
7c673cae FG |
35 | inline uint32_t GetSliceHash(const Slice& s) { |
36 | return Hash(s.data(), s.size(), 397); | |
37 | } | |
38 | ||
494da23a TL |
39 | inline uint64_t NPHash64(const char* data, size_t n, uint32_t seed) { |
40 | // Right now murmurhash2B is used. It should able to be freely | |
41 | // changed to a better hash, without worrying about backward | |
42 | // compatibility issue. | |
43 | return MURMUR_HASH(data, static_cast<int>(n), | |
44 | static_cast<unsigned int>(seed)); | |
45 | } | |
46 | ||
7c673cae FG |
47 | // std::hash compatible interface. |
48 | struct SliceHasher { | |
49 | uint32_t operator()(const Slice& s) const { return GetSliceHash(s); } | |
50 | }; | |
51 | ||
52 | } // namespace rocksdb |