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.
9 typedef unsigned int uint32_t;
11 inline uint32_t DecodeFixed32(const char* ptr
) {
12 if (true) { //port::kLittleEndian
15 memcpy(&result
, ptr
, sizeof(result
)); // gcc optimizes this to a plain load
18 return ((static_cast<uint32_t>(ptr
[0]))
19 | (static_cast<uint32_t>(ptr
[1]) << 8)
20 | (static_cast<uint32_t>(ptr
[2]) << 16)
21 | (static_cast<uint32_t>(ptr
[3]) << 24));
25 uint32_t Hash(const char* data
, size_t n
, uint32_t seed
) {
26 // Similar to murmur hash
27 const uint32_t m
= 0xc6a4a793;
28 const uint32_t r
= 24;
29 const char* limit
= data
+ n
;
30 uint32_t h
= seed
^ (n
* m
);
32 // Pick up four bytes at a time
33 while (data
+ 4 <= limit
) {
34 uint32_t w
= DecodeFixed32(data
);
41 // Pick up remaining bytes
42 switch (limit
- data
) {