Rollup merge of #82434 - jyn514:hash, r=JohnTitor
Add more links between hash and btree collections - Link from `core::hash` to `HashMap` and `HashSet` - Link from HashMap and HashSet to the module-level documentation on when to use the collection - Link from several collections to Wikipedia articles on the general concept See also https://github.com/rust-lang/rust/pull/81989#issuecomment-783920840.
This commit is contained in:
commit
c99200fa53
@ -21,15 +21,15 @@ use Entry::*;
|
|||||||
/// We might temporarily have fewer elements during methods.
|
/// We might temporarily have fewer elements during methods.
|
||||||
pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT;
|
pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT;
|
||||||
|
|
||||||
// A tree in a `BTreeMap` is a tree in the `node` module with addtional invariants:
|
// A tree in a `BTreeMap` is a tree in the `node` module with additional invariants:
|
||||||
// - Keys must appear in ascending order (according to the key's type).
|
// - Keys must appear in ascending order (according to the key's type).
|
||||||
// - If the root node is internal, it must contain at least 1 element.
|
// - If the root node is internal, it must contain at least 1 element.
|
||||||
// - Every non-root node contains at least MIN_LEN elements.
|
// - Every non-root node contains at least MIN_LEN elements.
|
||||||
//
|
//
|
||||||
// An empty map may be represented both by the absense of a root node or by a
|
// An empty map may be represented both by the absence of a root node or by a
|
||||||
// root node that is an empty leaf.
|
// root node that is an empty leaf.
|
||||||
|
|
||||||
/// A map based on a B-Tree.
|
/// A map based on a [B-Tree].
|
||||||
///
|
///
|
||||||
/// B-Trees represent a fundamental compromise between cache-efficiency and actually minimizing
|
/// B-Trees represent a fundamental compromise between cache-efficiency and actually minimizing
|
||||||
/// the amount of work performed in a search. In theory, a binary search tree (BST) is the optimal
|
/// the amount of work performed in a search. In theory, a binary search tree (BST) is the optimal
|
||||||
@ -63,6 +63,7 @@ pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT;
|
|||||||
/// undefined behavior. This could include panics, incorrect results, aborts, memory leaks, and
|
/// undefined behavior. This could include panics, incorrect results, aborts, memory leaks, and
|
||||||
/// non-termination.
|
/// non-termination.
|
||||||
///
|
///
|
||||||
|
/// [B-Tree]: https://en.wikipedia.org/wiki/B-tree
|
||||||
/// [`Cell`]: core::cell::Cell
|
/// [`Cell`]: core::cell::Cell
|
||||||
/// [`RefCell`]: core::cell::RefCell
|
/// [`RefCell`]: core::cell::RefCell
|
||||||
///
|
///
|
||||||
|
@ -1,7 +1,13 @@
|
|||||||
//! Generic hashing support.
|
//! Generic hashing support.
|
||||||
//!
|
//!
|
||||||
//! This module provides a generic way to compute the hash of a value. The
|
//! This module provides a generic way to compute the [hash] of a value.
|
||||||
//! simplest way to make a type hashable is to use `#[derive(Hash)]`:
|
//! Hashes are most commonly used with [`HashMap`] and [`HashSet`].
|
||||||
|
//!
|
||||||
|
//! [hash]: https://en.wikipedia.org/wiki/Hash_function
|
||||||
|
//! [`HashMap`]: ../../std/collections/struct.HashMap.html
|
||||||
|
//! [`HashSet`]: ../../std/collections/struct.HashSet.html
|
||||||
|
//!
|
||||||
|
//! The simplest way to make a type hashable is to use `#[derive(Hash)]`:
|
||||||
//!
|
//!
|
||||||
//! # Examples
|
//! # Examples
|
||||||
//!
|
//!
|
||||||
|
@ -17,7 +17,7 @@ use crate::iter::{FromIterator, FusedIterator};
|
|||||||
use crate::ops::Index;
|
use crate::ops::Index;
|
||||||
use crate::sys;
|
use crate::sys;
|
||||||
|
|
||||||
/// A hash map implemented with quadratic probing and SIMD lookup.
|
/// A [hash map] implemented with quadratic probing and SIMD lookup.
|
||||||
///
|
///
|
||||||
/// By default, `HashMap` uses a hashing algorithm selected to provide
|
/// By default, `HashMap` uses a hashing algorithm selected to provide
|
||||||
/// resistance against HashDoS attacks. The algorithm is randomly seeded, and a
|
/// resistance against HashDoS attacks. The algorithm is randomly seeded, and a
|
||||||
@ -62,6 +62,7 @@ use crate::sys;
|
|||||||
/// The original C++ version of SwissTable can be found [here], and this
|
/// The original C++ version of SwissTable can be found [here], and this
|
||||||
/// [CppCon talk] gives an overview of how the algorithm works.
|
/// [CppCon talk] gives an overview of how the algorithm works.
|
||||||
///
|
///
|
||||||
|
/// [hash map]: crate::collections#use-a-hashmap-when
|
||||||
/// [hashing algorithms available on crates.io]: https://crates.io/keywords/hasher
|
/// [hashing algorithms available on crates.io]: https://crates.io/keywords/hasher
|
||||||
/// [SwissTable]: https://abseil.io/blog/20180927-swisstables
|
/// [SwissTable]: https://abseil.io/blog/20180927-swisstables
|
||||||
/// [here]: https://github.com/abseil/abseil-cpp/blob/master/absl/container/internal/raw_hash_set.h
|
/// [here]: https://github.com/abseil/abseil-cpp/blob/master/absl/container/internal/raw_hash_set.h
|
||||||
|
@ -19,7 +19,7 @@ use super::map::{map_try_reserve_error, RandomState};
|
|||||||
// for `bucket.val` in the case of HashSet. I suppose we would need HKT
|
// for `bucket.val` in the case of HashSet. I suppose we would need HKT
|
||||||
// to get rid of it properly.
|
// to get rid of it properly.
|
||||||
|
|
||||||
/// A hash set implemented as a `HashMap` where the value is `()`.
|
/// A [hash set] implemented as a `HashMap` where the value is `()`.
|
||||||
///
|
///
|
||||||
/// As with the [`HashMap`] type, a `HashSet` requires that the elements
|
/// As with the [`HashMap`] type, a `HashSet` requires that the elements
|
||||||
/// implement the [`Eq`] and [`Hash`] traits. This can frequently be achieved by
|
/// implement the [`Eq`] and [`Hash`] traits. This can frequently be achieved by
|
||||||
@ -105,6 +105,7 @@ use super::map::{map_try_reserve_error, RandomState};
|
|||||||
/// // use the values stored in the set
|
/// // use the values stored in the set
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
|
/// [hash set]: crate::collections#use-the-set-variant-of-any-of-these-maps-when
|
||||||
/// [`HashMap`]: crate::collections::HashMap
|
/// [`HashMap`]: crate::collections::HashMap
|
||||||
/// [`RefCell`]: crate::cell::RefCell
|
/// [`RefCell`]: crate::cell::RefCell
|
||||||
/// [`Cell`]: crate::cell::Cell
|
/// [`Cell`]: crate::cell::Cell
|
||||||
|
Loading…
Reference in New Issue
Block a user