murmurhash.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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).
  5. //
  6. /*
  7. Murmurhash from http://sites.google.com/site/murmurhash/
  8. All code is released to the public domain. For business purposes, Murmurhash
  9. is under the MIT license.
  10. */
  11. #pragma once
  12. #include <stdint.h>
  13. #include "rocksdb/slice.h"
  14. #if defined(__x86_64__)
  15. #define MURMUR_HASH MurmurHash64A
  16. uint64_t MurmurHash64A ( const void * key, int len, unsigned int seed );
  17. #define MurmurHash MurmurHash64A
  18. typedef uint64_t murmur_t;
  19. #elif defined(__i386__)
  20. #define MURMUR_HASH MurmurHash2
  21. unsigned int MurmurHash2 ( const void * key, int len, unsigned int seed );
  22. #define MurmurHash MurmurHash2
  23. typedef unsigned int murmur_t;
  24. #else
  25. #define MURMUR_HASH MurmurHashNeutral2
  26. unsigned int MurmurHashNeutral2 ( const void * key, int len, unsigned int seed );
  27. #define MurmurHash MurmurHashNeutral2
  28. typedef unsigned int murmur_t;
  29. #endif
  30. // Allow slice to be hashable by murmur hash.
  31. namespace ROCKSDB_NAMESPACE {
  32. struct murmur_hash {
  33. size_t operator()(const Slice& slice) const {
  34. return MurmurHash(slice.data(), static_cast<int>(slice.size()), 0);
  35. }
  36. };
  37. } // namespace ROCKSDB_NAMESPACE