Bug: 239855775

Clone this repo:
  1. f7863a4 Migrate 25 crates to monorepo by James Farrell · 4 months ago main master
  2. c49a8a5 Fix license file issues. by James Farrell · 4 months ago
  3. 6aeb3ba Update Android.bp by running cargo_embargo by James Farrell · 4 months ago
  4. 9a1fdd8 Update Android.bp by running cargo_embargo am: d1e41633d7 am: 9894bf9e4f by James Farrell · 8 months ago android15-automotiveos-dev android15-qpr1-release android15-qpr1-s3-release android15-qpr1-s4-release android15-qpr1-s5-release android15-tests-dev aml_adb_351010000 aml_ads_350923060 aml_ads_351017080 aml_ads_351121120 aml_art_350913340 aml_art_351011240 aml_art_351011340 aml_art_351110180 aml_ase_351010000 aml_ase_351112060 aml_ase_351114000 aml_cbr_350910020 aml_cbr_351011020 aml_cbr_351111000 aml_cfg_351010000 aml_con_351010000 aml_con_351110000 aml_doc_350915120 aml_doc_351012120 aml_doc_351113060 aml_ext_350912020 aml_ext_351122080 aml_hef_350921160 aml_hef_351016140 aml_ips_351010000 aml_ips_351111040 aml_med_350914000 aml_med_351010060 aml_mpr_350914160 aml_mpr_351013100 aml_mpr_351013160 aml_net_350911020 aml_net_351010000 aml_net_351010020 aml_net_351111100 aml_net_351111140 aml_neu_351010000 aml_odp_350923040 aml_odp_351020000 aml_odp_351121040 aml_per_350910080 aml_per_351014000 aml_per_351112280 aml_per_351112300 aml_res_351011000 aml_res_351111020 aml_rkp_350910000 aml_rkp_351011000 aml_sch_351010000 aml_sdk_350910000 aml_sdk_351110000 aml_sta_350911020 aml_sta_351110040 aml_swc_350914020 aml_swc_350914040 aml_swc_350914060 aml_swc_351010060 aml_tet_350911120 aml_tet_351010220 aml_tet_351110060 aml_uwb_350911040 aml_uwb_351011040 android-15.0.0_r10 android-15.0.0_r11 android-15.0.0_r12 android-15.0.0_r13 android-15.0.0_r6 android-15.0.0_r7 android-15.0.0_r8 android-15.0.0_r9
  5. 9894bf9 Update Android.bp by running cargo_embargo am: d1e41633d7 by James Farrell · 8 months ago

Fx Hash

This 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.

Disclaimer

It 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 HashMaps. So it is not recommended to expose this hash in places where collissions or DDOS attacks may be a concern.

Examples

Building an Fx backed hashmap.

extern crate fxhash;
use fxhash::FxHashMap;

let mut hashmap = FxHashMap::new();

hashmap.insert("black", 0);
hashmap.insert("white", 255);

Building an Fx backed hashset.

extern crate fxhash;
use fxhash::FxHashSet;

let mut hashmap = FxHashSet::new();

hashmap.insert("black");
hashmap.insert("white");

Benchmarks

Generally 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.

bench_fnv_003     ... bench:      3 ns/iter (+/- 0)
bench_fnv_004     ... bench:      2 ns/iter (+/- 0)
bench_fnv_011     ... bench:      6 ns/iter (+/- 1)
bench_fnv_012     ... bench:      5 ns/iter (+/- 1)
bench_fnv_023     ... bench:     14 ns/iter (+/- 3)
bench_fnv_024     ... bench:     14 ns/iter (+/- 4)
bench_fnv_068     ... bench:     57 ns/iter (+/- 11)
bench_fnv_132     ... bench:    145 ns/iter (+/- 30)
bench_fx_003      ... bench:      4 ns/iter (+/- 0)
bench_fx_004      ... bench:      3 ns/iter (+/- 1)
bench_fx_011      ... bench:      5 ns/iter (+/- 2)
bench_fx_012      ... bench:      4 ns/iter (+/- 1)
bench_fx_023      ... bench:      7 ns/iter (+/- 3)
bench_fx_024      ... bench:      4 ns/iter (+/- 1)
bench_fx_068      ... bench:     10 ns/iter (+/- 3)
bench_fx_132      ... bench:     19 ns/iter (+/- 5)
bench_seahash_003 ... bench:     30 ns/iter (+/- 12)
bench_seahash_004 ... bench:     32 ns/iter (+/- 22)
bench_seahash_011 ... bench:     30 ns/iter (+/- 4)
bench_seahash_012 ... bench:     31 ns/iter (+/- 1)
bench_seahash_023 ... bench:     32 ns/iter (+/- 6)
bench_seahash_024 ... bench:     31 ns/iter (+/- 5)
bench_seahash_068 ... bench:     40 ns/iter (+/- 9)
bench_seahash_132 ... bench:     50 ns/iter (+/- 12)