1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/other-licenses/nsis/Contrib/CityHash/cityhash/city.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,91 @@ 1.4 +// Copyright (c) 2011 Google, Inc. 1.5 +// 1.6 +// Permission is hereby granted, free of charge, to any person obtaining a copy 1.7 +// of this software and associated documentation files (the "Software"), to deal 1.8 +// in the Software without restriction, including without limitation the rights 1.9 +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 1.10 +// copies of the Software, and to permit persons to whom the Software is 1.11 +// furnished to do so, subject to the following conditions: 1.12 +// 1.13 +// The above copyright notice and this permission notice shall be included in 1.14 +// all copies or substantial portions of the Software. 1.15 +// 1.16 +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1.17 +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1.18 +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1.19 +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1.20 +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 1.21 +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 1.22 +// THE SOFTWARE. 1.23 +// 1.24 +// CityHash Version 1, by Geoff Pike and Jyrki Alakuijala 1.25 +// 1.26 +// This file provides a few functions for hashing strings. On x86-64 1.27 +// hardware in 2011, CityHash64() is faster than other high-quality 1.28 +// hash functions, such as Murmur. This is largely due to higher 1.29 +// instruction-level parallelism. CityHash64() and CityHash128() also perform 1.30 +// well on hash-quality tests. 1.31 +// 1.32 +// CityHash128() is optimized for relatively long strings and returns 1.33 +// a 128-bit hash. For strings more than about 2000 bytes it can be 1.34 +// faster than CityHash64(). 1.35 +// 1.36 +// Functions in the CityHash family are not suitable for cryptography. 1.37 +// 1.38 +// WARNING: This code has not been tested on big-endian platforms! 1.39 +// It is known to work well on little-endian platforms that have a small penalty 1.40 +// for unaligned reads, such as current Intel and AMD moderate-to-high-end CPUs. 1.41 +// 1.42 +// By the way, for some hash functions, given strings a and b, the hash 1.43 +// of a+b is easily derived from the hashes of a and b. This property 1.44 +// doesn't hold for any hash functions in this file. 1.45 + 1.46 +#ifndef CITY_HASH_H_ 1.47 +#define CITY_HASH_H_ 1.48 + 1.49 +#include "../CityHash.h" // added by moz, specific to nsis project 1.50 + 1.51 +#include <stdlib.h> // for size_t. 1.52 +#include <utility> 1.53 + 1.54 +typedef unsigned __int8 uint8; 1.55 +typedef unsigned __int32 uint32; 1.56 +typedef unsigned __int64 uint64; 1.57 +typedef std::pair<uint64, uint64> uint128; 1.58 + 1.59 +inline uint64 Uint128Low64(const uint128& x) { return x.first; } 1.60 +inline uint64 Uint128High64(const uint128& x) { return x.second; } 1.61 + 1.62 +// Hash function for a byte array. 1.63 +uint64 CityHash64(const char *buf, size_t len); 1.64 + 1.65 +// Hash function for a byte array. For convenience, a 64-bit seed is also 1.66 +// hashed into the result. 1.67 +uint64 CityHash64WithSeed(const char *buf, size_t len, uint64 seed); 1.68 + 1.69 +// Hash function for a byte array. For convenience, two seeds are also 1.70 +// hashed into the result. 1.71 +uint64 CityHash64WithSeeds(const char *buf, size_t len, 1.72 + uint64 seed0, uint64 seed1); 1.73 + 1.74 +// Hash function for a byte array. 1.75 +uint128 CityHash128(const char *s, size_t len); 1.76 + 1.77 +// Hash function for a byte array. For convenience, a 128-bit seed is also 1.78 +// hashed into the result. 1.79 +uint128 CityHash128WithSeed(const char *s, size_t len, uint128 seed); 1.80 + 1.81 +// Hash 128 input bits down to 64 bits of output. 1.82 +// This is intended to be a reasonably good hash function. 1.83 +inline uint64 Hash128to64(const uint128& x) { 1.84 + // Murmur-inspired hashing. 1.85 + const uint64 kMul = 0x9ddfea08eb382d69; 1.86 + uint64 a = (Uint128Low64(x) ^ Uint128High64(x)) * kMul; 1.87 + a ^= (a >> 47); 1.88 + uint64 b = (Uint128High64(x) ^ a) * kMul; 1.89 + b ^= (b >> 47); 1.90 + b *= kMul; 1.91 + return b; 1.92 +} 1.93 + 1.94 +#endif // CITY_HASH_H_