Skip to content

Commit 33bdfed

Browse files
committed
Merge branch 'release/v0.2.1'
2 parents 4211324 + 8c504a5 commit 33bdfed

File tree

20 files changed

+653
-255
lines changed

20 files changed

+653
-255
lines changed

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,41 @@ fn hash<T: Hash>(t: &T) -> u64 {
3939
hash(&"hello world");
4040
```
4141

42+
It also cowork with `HashMap` or `HashSet`, act as a hash function
43+
44+
```rust
45+
use std::collections::HashSet;
46+
47+
use fasthash::spooky::SpookyHash128;
48+
49+
let mut set = HashSet::with_hasher(SpookyHash128 {});
50+
set.insert(2);
51+
```
52+
53+
Or use RandomState<CityHash64> with a random seed.
54+
55+
```rust
56+
use std::hash::{Hash, Hasher};
57+
use std::collections::HashMap;
58+
59+
use fasthash::RandomState;
60+
use fasthash::city::CityHash64;
61+
62+
let s = RandomState::<CityHash64>::new();
63+
let mut map = HashMap::with_hasher(s);
64+
65+
assert_eq!(map.insert(37, "a"), None);
66+
assert_eq!(map.is_empty(), false);
67+
68+
map.insert(37, "b");
69+
assert_eq!(map.insert(37, "c"), Some("b"));
70+
assert_eq!(map[&37], "c");
71+
```
72+
4273
# Goal
4374
- High performance
4475
- Zero cost
45-
- Compatibility with [Hasher](https://doc.rust-lang.org/std/hash/trait.Hasher.html)
76+
- Compatibility with libstd
4677

4778
# Features
4879

@@ -56,6 +87,9 @@ hash(&"hello world");
5687
- [x] [Spooky Hash](http://burtleburtle.net/bob/hash/spooky.html)
5788
- [x] [T1 Hash](https://github.com/leo-yuriev/t1ha)
5889
- [x] [xx Hash](https://github.com/Cyan4973/xxHash)
90+
- Compatibility
91+
- [x] [Hasher](https://doc.rust-lang.org/std/hash/trait.Hasher.html)
92+
- [x] std::collections::{[HashMap](https://doc.rust-lang.org/std/collections/struct.HashMap.html), [HashSet](https://doc.rust-lang.org/std/collections/struct.HashSet.html)} with `RandomState`
5993

6094
# Performance
6195

fasthash-sys/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "fasthash-sys"
3-
version = "0.2.0"
3+
version = "0.2.1"
44
authors = ["Flier Lu <flier.lu@gmail.com>"]
55
description = "A suite of non-cryptographic hash functions for Rust."
66
homepage = "https://github.com/flier/rust-fasthash"

fasthash-sys/build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ fn main() {
1010
gcc_config.file("src/fasthash.cpp")
1111
.file("src/smhasher/City.cpp")
1212
.file("src/smhasher/farmhash-c.c")
13+
.file("src/smhasher/lookup3.cpp")
1314
.file("src/smhasher/mum.cc")
1415
.file("src/smhasher/metrohash64.cpp")
1516
.file("src/smhasher/metrohash128.cpp")
@@ -41,6 +42,7 @@ fn main() {
4142
.no_unstable_rust()
4243
.whitelisted_function("^CityHash.*")
4344
.whitelisted_function("^farmhash.*")
45+
.whitelisted_function("^lookup3.*")
4446
.whitelisted_function("^metrohash.*")
4547
.whitelisted_function("^mum_hash.*")
4648
.whitelisted_function("^MurmurHash.*")

fasthash-sys/src/fasthash.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ uint64_t farmhash_fingerprint_uint128(uint128_c_t x);
1313

1414
uint64_t farmhash_fingerprint_uint64(uint64_t x);
1515

16+
uint32_t lookup3(const void * key, int length, uint32_t initval);
17+
1618
uint64_t mum_hash_(const void *key, size_t len, uint64_t seed);
1719

1820
void SpookyHasherHash(

fasthash/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ sse42 = ["fasthash-sys/sse42"]
1717

1818
[dependencies]
1919
extprim = "1.1"
20+
rand = "^0.3"
2021
seahash = "3.0"
21-
fasthash-sys = { version = "0.2.0", path = "../fasthash-sys" }
22+
fasthash-sys = { version = "0.2.1", path = "../fasthash-sys" }
2223

2324
[dev-dependencies]
24-
rand = "^0.3"
2525
fnv = "1.0"

fasthash/build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ fn main() {
2424

2525
let hashes = vec![("city", vec!["CityHash32", "CityHash64", "CityHash128", "CityHashCrc128"]),
2626
("farm", vec!["FarmHash32", "FarmHash64", "FarmHash128"]),
27+
("lookup3", vec!["Lookup3"]),
2728
("metro",
2829
vec!["MetroHash64_1",
2930
"MetroHash64_2",
@@ -72,6 +73,7 @@ fn bench_{name}_key_{keysize}(b: &mut Bencher) {{
7273
"CityHasherExt",
7374
"FarmHasher",
7475
"FarmHasherExt",
76+
"Lookup3Hasher",
7577
"MetroHasher",
7678
"MetroHasherExt",
7779
"MumHasher",

fasthash/src/city.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
//! use fasthash::{city, CityHasher};
111111
//!
112112
//! fn hash<T: Hash>(t: &T) -> u64 {
113-
//! let mut s = CityHasher::new();
113+
//! let mut s: CityHasher = Default::default();
114114
//! t.hash(&mut s);
115115
//! s.finish()
116116
//! }
@@ -126,7 +126,7 @@ use extprim::u128::u128;
126126

127127
use ffi;
128128

129-
use hasher::FastHash;
129+
use hasher::{FastHash, FastHasher};
130130

131131
/// CityHash 32-bit hash functions
132132
pub struct CityHash32 {}
@@ -145,7 +145,6 @@ impl FastHash for CityHash32 {
145145
}
146146
}
147147

148-
149148
impl_hasher!(CityHasher32, CityHash32);
150149

151150
/// CityHash 64-bit hash functions
@@ -275,13 +274,15 @@ pub fn hash64_with_seeds<T: AsRef<[u8]>>(v: &T, seed0: u64, seed1: u64) -> u64 {
275274
}
276275

277276
/// CityHash 128-bit hash function for a byte array.
277+
#[cfg(not(feature = "sse42"))]
278278
#[inline]
279279
pub fn hash128<T: AsRef<[u8]>>(v: &T) -> u128 {
280280
CityHash128::hash(v)
281281
}
282282

283283
/// CityHash 128-bit hash function for a byte array.
284284
/// For convenience, a 128-bit seed is also hashed into the result.
285+
#[cfg(not(feature = "sse42"))]
285286
#[inline]
286287
pub fn hash128_with_seed<T: AsRef<[u8]>>(v: &T, seed: u128) -> u128 {
287288
CityHash128::hash_with_seed(v, seed)
@@ -291,7 +292,7 @@ pub fn hash128_with_seed<T: AsRef<[u8]>>(v: &T, seed: u128) -> u128 {
291292
/// That require SSE4.2 instructions to be available.
292293
#[cfg(any(feature = "doc", feature = "sse42"))]
293294
#[inline]
294-
pub fn hash128crc<T: AsRef<[u8]>>(v: &T) -> u128 {
295+
pub fn hash128<T: AsRef<[u8]>>(v: &T) -> u128 {
295296
CityHashCrc128::hash(v)
296297
}
297298

@@ -300,7 +301,7 @@ pub fn hash128crc<T: AsRef<[u8]>>(v: &T) -> u128 {
300301
/// That require SSE4.2 instructions to be available.
301302
#[cfg(any(feature = "doc", feature = "sse42"))]
302303
#[inline]
303-
pub fn hash128crc_with_seed<T: AsRef<[u8]>>(v: &T, seed: u128) -> u128 {
304+
pub fn hash128_with_seed<T: AsRef<[u8]>>(v: &T, seed: u128) -> u128 {
304305
CityHashCrc128::hash_with_seed(v, seed)
305306
}
306307

@@ -310,7 +311,7 @@ mod tests {
310311

311312
use extprim::u128::u128;
312313

313-
use hasher::{FastHash, HasherExt};
314+
use hasher::{FastHash, FastHasher, HasherExt};
314315
use super::*;
315316

316317
#[test]

fasthash/src/farm.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
//! use fasthash::{farm, FarmHasher};
109109
//!
110110
//! fn hash<T: Hash>(t: &T) -> u64 {
111-
//! let mut s = FarmHasher::new();
111+
//! let mut s: FarmHasher = Default::default();
112112
//! t.hash(&mut s);
113113
//! s.finish()
114114
//! }
@@ -124,7 +124,7 @@ use extprim::u128::u128;
124124

125125
use ffi;
126126

127-
use hasher::{Fingerprint, FastHash};
127+
use hasher::{Fingerprint, FastHash, FastHasher};
128128

129129
/// FarmHash 32-bit hash functions
130130
pub struct FarmHash32 {}
@@ -319,7 +319,7 @@ mod tests {
319319

320320
use extprim::u128::u128;
321321

322-
use hasher::{Fingerprint, FastHash, HasherExt};
322+
use hasher::{Fingerprint, FastHash, FastHasher, HasherExt};
323323
use super::*;
324324

325325
#[test]

0 commit comments

Comments
 (0)