Skip to content

Commit ef32ef7

Browse files
Rollup merge of #77996 - tkaitchuck:master, r=m-ou-se
Doc change: Remove mention of `fnv` in HashMap Disclaimer: I am the author of [aHash](https://github.com/tkaitchuck/aHash). This changes the Rustdoc in `HashMap` from mentioning the `fnv` crate to mentioning the `aHash` crate, as an alternative `Hasher` implementation. ### Why Fnv [has poor hash quality](https://github.com/rurban/smhasher), is [slow for larger keys](https://github.com/tkaitchuck/aHash/blob/master/compare/readme.md#speed), and does not provide dos resistance, because it is unkeyed (this can also cause [other problems](https://accidentallyquadratic.tumblr.com/post/153545455987/rust-hash-iteration-reinsertion)). Fnv has acceptable performance for integers and has very poor performance with keys >32 bytes. This is the reason it was removed from the standard library in #37229 . Because regardless of which dimension you value, there are better alternatives, it does not make sense for anyone to consider using `fnv`. The text mentioning `fnv` in the standard library continues to create confusion: rust-lang/hashbrown#153 rust-lang/hashbrown#9 . There are also a number of [crates using it](https://crates.io/crates/fnv/reverse_dependencies) a great many of which are hashing strings (Which is when Fnv is the [worst](https://github.com/cbreeden/fxhash#benchmarks), [possible](https://github.com/tkaitchuck/aHash#speed), [choice](http://cglab.ca/~abeinges/blah/hash-rs/).) I think aHash makes the most sense to mention as an alternative because it is the most credible option (in my obviously biased opinion). It offers [good performance on numbers and strings](https://github.com/tkaitchuck/aHash/blob/master/compare/readme.md#speed), is [of high quality](https://github.com/tkaitchuck/aHash#hash-quality), and [provides dos resistance](https://github.com/tkaitchuck/aHash/wiki/How-aHash-is-resists-DOS-attacks). It is popular (see [stats](https://crates.io/crates/ahash)) and is the default hasher for [hashbrown](https://crates.io/crates/hashbrown) and [dashmap](https://crates.io/crates/dashmap) which are the most popular alternative hashmaps. Finally it does not have any of the [`gotcha` cases](https://github.com/tkaitchuck/aHash#fxhash) that `FxHash` suffers from. (Which is the other popular hashing option when DOS attacks are not a concern) Signed-off-by: Tom Kaitchuck <[email protected]>
2 parents c5a11dd + 4e58483 commit ef32ef7

File tree

1 file changed

+3
-3
lines changed
  • library/std/src/collections/hash

1 file changed

+3
-3
lines changed

library/std/src/collections/hash/map.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ use crate::sys;
3434
/// attacks such as HashDoS.
3535
///
3636
/// The hashing algorithm can be replaced on a per-`HashMap` basis using the
37-
/// [`default`], [`with_hasher`], and [`with_capacity_and_hasher`] methods. Many
38-
/// alternative algorithms are available on crates.io, such as the [`fnv`] crate.
37+
/// [`default`], [`with_hasher`], and [`with_capacity_and_hasher`] methods.
38+
/// There are many alternative [hashing algorithms available on crates.io].
3939
///
4040
/// It is required that the keys implement the [`Eq`] and [`Hash`] traits, although
4141
/// this can frequently be achieved by using `#[derive(PartialEq, Eq, Hash)]`.
@@ -57,6 +57,7 @@ use crate::sys;
5757
/// The original C++ version of SwissTable can be found [here], and this
5858
/// [CppCon talk] gives an overview of how the algorithm works.
5959
///
60+
/// [hashing algorithms available on crates.io]: https://crates.io/keywords/hasher
6061
/// [SwissTable]: https://abseil.io/blog/20180927-swisstables
6162
/// [here]: https://github.com/abseil/abseil-cpp/blob/master/absl/container/internal/raw_hash_set.h
6263
/// [CppCon talk]: https://www.youtube.com/watch?v=ncHmEUmJZf4
@@ -154,7 +155,6 @@ use crate::sys;
154155
/// [`default`]: Default::default
155156
/// [`with_hasher`]: Self::with_hasher
156157
/// [`with_capacity_and_hasher`]: Self::with_capacity_and_hasher
157-
/// [`fnv`]: https://crates.io/crates/fnv
158158
///
159159
/// ```
160160
/// use std::collections::HashMap;

0 commit comments

Comments
 (0)