• Home
Name Date Size #Lines LOC

..--

Android.bpD03-May-20241.8 KiB5953

Cargo.tomlD03-May-20241.1 KiB3934

Cargo.toml.origD03-May-2024564 2622

LICENSED03-May-20241.1 KiB2217

LICENSE-APACHED03-May-202411.1 KiB202169

LICENSE-MITD03-May-20241.1 KiB2217

METADATAD03-May-2024507 2120

MODULE_LICENSE_APACHE2D03-May-20240

OWNERSD03-May-202447 21

README.mdD03-May-20242.7 KiB6247

TEST_MAPPINGD03-May-2024156 98

bench.rsD03-May-20242.5 KiB7868

lib.rsD03-May-20248.3 KiB324223

README.md

1# Fx Hash
2
3This hashing algorithm was extracted from the Rustc compiler.  This is the same hashing algoirthm used for some internal operations in FireFox.  The strength of this algorithm is in hashing 8 bytes at a time on 64-bit platforms, where the FNV algorithm works on one byte at a time.
4
5## Disclaimer
6
7It is **not a cryptographically secure** hash, so it is strongly recommended that you do not use this hash for cryptographic purproses.  Furthermore, this hashing algorithm was not designed to prevent any attacks for determining collisions which could be used to potentially cause quadratic behavior in `HashMap`s.  So it is not recommended to expose this hash in places where collissions or DDOS attacks may be a concern.
8
9## Examples
10
11Building an Fx backed hashmap.
12
13```rust
14extern crate fxhash;
15use fxhash::FxHashMap;
16
17let mut hashmap = FxHashMap::new();
18
19hashmap.insert("black", 0);
20hashmap.insert("white", 255);
21```
22
23Building an Fx backed hashset.
24
25```rust
26extern crate fxhash;
27use fxhash::FxHashSet;
28
29let mut hashmap = FxHashSet::new();
30
31hashmap.insert("black");
32hashmap.insert("white");
33```
34
35## Benchmarks
36
37Generally `fxhash` is than `fnv` on `u32`, `u64`, or any byte sequence with length >= 5.  However, keep in mind that hashing speed is not the only characteristic worth considering.  That being said, Rustc had an observable increase in speed when switching from `fnv` backed hashmaps to `fx` based hashmaps.
38
39    bench_fnv_003     ... bench:      3 ns/iter (+/- 0)
40    bench_fnv_004     ... bench:      2 ns/iter (+/- 0)
41    bench_fnv_011     ... bench:      6 ns/iter (+/- 1)
42    bench_fnv_012     ... bench:      5 ns/iter (+/- 1)
43    bench_fnv_023     ... bench:     14 ns/iter (+/- 3)
44    bench_fnv_024     ... bench:     14 ns/iter (+/- 4)
45    bench_fnv_068     ... bench:     57 ns/iter (+/- 11)
46    bench_fnv_132     ... bench:    145 ns/iter (+/- 30)
47    bench_fx_003      ... bench:      4 ns/iter (+/- 0)
48    bench_fx_004      ... bench:      3 ns/iter (+/- 1)
49    bench_fx_011      ... bench:      5 ns/iter (+/- 2)
50    bench_fx_012      ... bench:      4 ns/iter (+/- 1)
51    bench_fx_023      ... bench:      7 ns/iter (+/- 3)
52    bench_fx_024      ... bench:      4 ns/iter (+/- 1)
53    bench_fx_068      ... bench:     10 ns/iter (+/- 3)
54    bench_fx_132      ... bench:     19 ns/iter (+/- 5)
55    bench_seahash_003 ... bench:     30 ns/iter (+/- 12)
56    bench_seahash_004 ... bench:     32 ns/iter (+/- 22)
57    bench_seahash_011 ... bench:     30 ns/iter (+/- 4)
58    bench_seahash_012 ... bench:     31 ns/iter (+/- 1)
59    bench_seahash_023 ... bench:     32 ns/iter (+/- 6)
60    bench_seahash_024 ... bench:     31 ns/iter (+/- 5)
61    bench_seahash_068 ... bench:     40 ns/iter (+/- 9)
62    bench_seahash_132 ... bench:     50 ns/iter (+/- 12)