2016-02-10 00:12:00 +01:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-16 01:03:42 +02:00
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
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
|