]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/util/hash.h
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
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).
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.
10 // Simple hash function used for internal data structures
16 #include "rocksdb/slice.h"
17 #include "util/murmurhash.h"
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
);
25 extern uint32_t Hash(const char* data
, size_t n
, uint32_t seed
);
27 inline uint32_t BloomHash(const Slice
& key
) {
28 return Hash(key
.data(), key
.size(), 0xbc9f1d34);
31 inline uint64_t GetSliceNPHash64(const Slice
& s
) {
32 return NPHash64(s
.data(), s
.size(), 0);
35 inline uint32_t GetSliceHash(const Slice
& s
) {
36 return Hash(s
.data(), s
.size(), 397);
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
));
47 // std::hash compatible interface.
49 uint32_t operator()(const Slice
& s
) const { return GetSliceHash(s
); }
52 } // namespace rocksdb