2016-02-10 00:12:00 +01:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2013-10-16 23:59:46 +02:00
|
|
|
// This source code is licensed under the BSD-style license found in the
|
|
|
|
// LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
// of patent rights can be found in the PATENTS file in the same directory.
|
2017-04-28 02:50:56 +02:00
|
|
|
// This source code is also licensed under the GPLv2 license found in the
|
|
|
|
// COPYING file in the root directory of this source tree.
|
2013-10-16 23:59:46 +02:00
|
|
|
//
|
2011-03-18 23:37:00 +01:00
|
|
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
//
|
|
|
|
// Simple hash function used for internal data structures
|
|
|
|
|
2013-10-05 07:32:05 +02:00
|
|
|
#pragma once
|
2011-03-18 23:37:00 +01:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2016-07-15 19:41:36 +02:00
|
|
|
#include "rocksdb/slice.h"
|
|
|
|
|
2013-10-04 06:49:15 +02:00
|
|
|
namespace rocksdb {
|
2011-03-18 23:37:00 +01:00
|
|
|
|
|
|
|
extern uint32_t Hash(const char* data, size_t n, uint32_t seed);
|
|
|
|
|
2014-08-07 19:05:04 +02:00
|
|
|
inline uint32_t BloomHash(const Slice& key) {
|
|
|
|
return Hash(key.data(), key.size(), 0xbc9f1d34);
|
|
|
|
}
|
|
|
|
|
2014-07-19 01:58:13 +02:00
|
|
|
inline uint32_t GetSliceHash(const Slice& s) {
|
|
|
|
return Hash(s.data(), s.size(), 397);
|
|
|
|
}
|
2014-11-20 19:49:32 +01:00
|
|
|
|
2016-11-14 03:58:17 +01:00
|
|
|
// std::hash compatible interface.
|
|
|
|
struct SliceHasher {
|
|
|
|
uint32_t operator()(const Slice& s) const { return GetSliceHash(s); }
|
|
|
|
};
|
|
|
|
|
2014-11-20 19:49:32 +01:00
|
|
|
} // namespace rocksdb
|