1 // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. See the AUTHORS file for names of contributors.
6 #include "util/coding.h"
9 // The FALLTHROUGH_INTENDED macro can be used to annotate implicit fall-through
10 // between switch labels. The real definition should be provided externally.
11 // This one is a fallback version for unsupported compilers.
12 #ifndef FALLTHROUGH_INTENDED
13 #define FALLTHROUGH_INTENDED do { } while (0)
18 uint32_t Hash(const char* data, size_t n, uint32_t seed) {
19 // Similar to murmur hash
20 const uint32_t m = 0xc6a4a793;
21 const uint32_t r = 24;
22 const char* limit = data + n;
23 uint32_t h = seed ^ (n * m);
25 // Pick up four bytes at a time
26 while (data + 4 <= limit) {
27 uint32_t w = DecodeFixed32(data);
34 // Pick up remaining bytes
35 switch (limit - data) {
52 } // namespace leveldb