/Users/deen/code/yugabyte-db/src/yb/rocksdb/util/hash.h
Line | Count | Source |
1 | | // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. |
2 | | // This source code is licensed under the BSD-style license found in the |
3 | | // LICENSE file in the root directory of this source tree. An additional grant |
4 | | // of patent rights can be found in the PATENTS file in the same directory. |
5 | | // |
6 | | // The following only applies to changes made to this file as part of YugaByte development. |
7 | | // |
8 | | // Portions Copyright (c) YugaByte, Inc. |
9 | | // |
10 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
11 | | // in compliance with the License. You may obtain a copy of the License at |
12 | | // |
13 | | // http://www.apache.org/licenses/LICENSE-2.0 |
14 | | // |
15 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
16 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
17 | | // or implied. See the License for the specific language governing permissions and limitations |
18 | | // under the License. |
19 | | // |
20 | | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. |
21 | | // Use of this source code is governed by a BSD-style license that can be |
22 | | // found in the LICENSE file. See the AUTHORS file for names of contributors. |
23 | | // |
24 | | // Simple hash function used for internal data structures |
25 | | #ifndef YB_ROCKSDB_UTIL_HASH_H |
26 | | #define YB_ROCKSDB_UTIL_HASH_H |
27 | | |
28 | | #pragma once |
29 | | #include <stddef.h> |
30 | | #include <stdint.h> |
31 | | |
32 | | #include "yb/util/slice.h" |
33 | | |
34 | | namespace rocksdb { |
35 | | |
36 | | uint32_t Hash(const char* data, size_t n, uint32_t seed); |
37 | | |
38 | 78.0M | inline uint32_t Hash(const uint8_t* data, size_t n, uint32_t seed) { |
39 | 78.0M | return Hash(reinterpret_cast<const char*>(data), n, seed); |
40 | 78.0M | } |
41 | | |
42 | 30.2M | inline uint32_t BloomHash(const Slice& key) { |
43 | 30.2M | return Hash(key.data(), key.size(), 0xbc9f1d34); |
44 | 30.2M | } |
45 | | |
46 | 1.47M | inline uint32_t GetSliceHash(const Slice& s) { |
47 | 1.47M | return Hash(s.data(), s.size(), 397); |
48 | 1.47M | } |
49 | | |
50 | | } // namespace rocksdb |
51 | | |
52 | | #endif // YB_ROCKSDB_UTIL_HASH_H |