Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
city.hpp
Go to the documentation of this file.
1// Copyright (c) 2011 Google, Inc.
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20//
21// CityHash, by Geoff Pike and Jyrki Alakuijala
22//
23// This file provides a few functions for hashing strings. On x86-64
24// hardware in 2011, CityHash64() is faster than other high-quality
25// hash functions, such as Murmur. This is largely due to higher
26// instruction-level parallelism. CityHash64() and CityHash128() also perform
27// well on hash-quality tests.
28//
29// CityHash128() is optimized for relatively long strings and returns
30// a 128-bit hash. For strings more than about 2000 bytes it can be
31// faster than CityHash64().
32//
33// Functions in the CityHash family are not suitable for cryptography.
34//
35// WARNING: This code has not been 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//
39// By the way, for some hash functions, given strings a and b, the hash
40// of a+b is easily derived from the hashes of a and b. This property
41// doesn't hold for any hash functions in this file.
42#pragma once
43
44#include <stdlib.h> // for size_t.
45#include <stdint.h>
46#include <utility>
47
48namespace fc {
49
50template<typename T, size_t N>
51class array;
52class uint128;
53
54// Hash function for a byte array.
55uint64_t city_hash64(const char *buf, size_t len);
56
57uint32_t city_hash32(const char *buf, size_t len);
58
59#if SIZE_MAX > UINT32_MAX
60inline size_t city_hash_size_t(const char *buf, size_t len) { return city_hash64(buf, len); }
61#else
62inline size_t city_hash_size_t(const char *buf, size_t len) { return city_hash32(buf, len); }
63#endif
64
65// Hash function for a byte array.
66uint128 city_hash128(const char *s, size_t len);
67
68// Hash function for a byte array.
69uint64_t city_hash_crc_64(const char *buf, size_t len);
70
71// Hash function for a byte array.
72uint128 city_hash_crc_128(const char *s, size_t len);
73array<uint64_t,4> city_hash_crc_256(const char *s, size_t len);
74
75
76} // namespace fc
an implementation of 128 bit unsigned integer
Definition uint128.hpp:22
namespace sysio::chain
Definition authority.cpp:3
uint64_t city_hash_crc_64(const char *buf, size_t len)
uint32_t city_hash32(const char *buf, size_t len)
Definition city.cpp:217
uint128 city_hash128(const char *s, size_t len)
Definition city.cpp:536
size_t city_hash_size_t(const char *buf, size_t len)
Definition city.hpp:62
uint64_t city_hash64(const char *buf, size_t len)
Definition city.cpp:394
uint128 city_hash_crc_128(const char *s, size_t len)
Definition city.cpp:671
array< uint64_t, 4 > city_hash_crc_256(const char *s, size_t len)
Definition city.cpp:651
unsigned int uint32_t
Definition stdint.h:126
unsigned __int64 uint64_t
Definition stdint.h:136
char * s
size_t len
uint8_t buf[2048]