1 // Copyright 2018 The Abseil Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 // https://code.google.com/p/cityhash/ 16 // 17 // This file provides a few functions for hashing strings. All of them are 18 // high-quality functions in the sense that they pass standard tests such 19 // as Austin Appleby's SMHasher. They are also fast. 20 // 21 // For 64-bit x86 code, on short strings, we don't know of anything faster than 22 // CityHash64 that is of comparable quality. We believe our nearest competitor 23 // is Murmur3. For 64-bit x86 code, CityHash64 is an excellent choice for hash 24 // tables and most other hashing (excluding cryptography). 25 // 26 // For 32-bit x86 code, we don't know of anything faster than CityHash32 that 27 // is of comparable quality. We believe our nearest competitor is Murmur3A. 28 // (On 64-bit CPUs, it is typically faster to use the other CityHash variants.) 29 // 30 // Functions in the CityHash family are not suitable for cryptography. 31 // 32 // Please see CityHash's README file for more details on our performance 33 // measurements and so on. 34 // 35 // WARNING: This code has been only lightly tested on big-endian platforms! 36 // It is known to work well on little-endian platforms that have a small penalty 37 // for unaligned reads, such as current Intel and AMD moderate-to-high-end CPUs. 38 // It should work on all 32-bit and 64-bit platforms that allow unaligned reads; 39 // bug reports are welcome. 40 // 41 // By the way, for some hash functions, given strings a and b, the hash 42 // of a+b is easily derived from the hashes of a and b. This property 43 // doesn't hold for any hash functions in this file. 44 45 #ifndef ABSL_HASH_INTERNAL_CITY_H_ 46 #define ABSL_HASH_INTERNAL_CITY_H_ 47 48 #include <stdint.h> 49 #include <stdlib.h> // for size_t. 50 51 #include <utility> 52 53 #include "absl/base/config.h" 54 55 namespace absl { 56 ABSL_NAMESPACE_BEGIN 57 namespace hash_internal { 58 59 // Hash function for a byte array. 60 uint64_t CityHash64(const char *s, size_t len); 61 62 // Hash function for a byte array. For convenience, a 64-bit seed is also 63 // hashed into the result. 64 uint64_t CityHash64WithSeed(const char *s, size_t len, uint64_t seed); 65 66 // Hash function for a byte array. For convenience, two seeds are also 67 // hashed into the result. 68 uint64_t CityHash64WithSeeds(const char *s, size_t len, uint64_t seed0, 69 uint64_t seed1); 70 71 // Hash function for a byte array. Most useful in 32-bit binaries. 72 uint32_t CityHash32(const char *s, size_t len); 73 74 } // namespace hash_internal 75 ABSL_NAMESPACE_END 76 } // namespace absl 77 78 #endif // ABSL_HASH_INTERNAL_CITY_H_ 79