Skip to content

Commit c99200f

Browse files
authored
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 #81989 (comment).
2 parents 16f6583 + a7491d9 commit c99200f

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

library/alloc/src/collections/btree/map.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ use Entry::*;
2121
/// We might temporarily have fewer elements during methods.
2222
pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT;
2323

24-
// A tree in a `BTreeMap` is a tree in the `node` module with addtional invariants:
24+
// A tree in a `BTreeMap` is a tree in the `node` module with additional invariants:
2525
// - Keys must appear in ascending order (according to the key's type).
2626
// - If the root node is internal, it must contain at least 1 element.
2727
// - Every non-root node contains at least MIN_LEN elements.
2828
//
29-
// An empty map may be represented both by the absense of a root node or by a
29+
// An empty map may be represented both by the absence of a root node or by a
3030
// root node that is an empty leaf.
3131

32-
/// A map based on a B-Tree.
32+
/// A map based on a [B-Tree].
3333
///
3434
/// B-Trees represent a fundamental compromise between cache-efficiency and actually minimizing
3535
/// 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;
6363
/// undefined behavior. This could include panics, incorrect results, aborts, memory leaks, and
6464
/// non-termination.
6565
///
66+
/// [B-Tree]: https://en.wikipedia.org/wiki/B-tree
6667
/// [`Cell`]: core::cell::Cell
6768
/// [`RefCell`]: core::cell::RefCell
6869
///

library/core/src/hash/mod.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
//! Generic hashing support.
22
//!
3-
//! This module provides a generic way to compute the hash of a value. The
4-
//! simplest way to make a type hashable is to use `#[derive(Hash)]`:
3+
//! This module provides a generic way to compute the [hash] of a value.
4+
//! Hashes are most commonly used with [`HashMap`] and [`HashSet`].
5+
//!
6+
//! [hash]: https://en.wikipedia.org/wiki/Hash_function
7+
//! [`HashMap`]: ../../std/collections/struct.HashMap.html
8+
//! [`HashSet`]: ../../std/collections/struct.HashSet.html
9+
//!
10+
//! The simplest way to make a type hashable is to use `#[derive(Hash)]`:
511
//!
612
//! # Examples
713
//!

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::iter::{FromIterator, FusedIterator};
1717
use crate::ops::Index;
1818
use crate::sys;
1919

20-
/// A hash map implemented with quadratic probing and SIMD lookup.
20+
/// A [hash map] implemented with quadratic probing and SIMD lookup.
2121
///
2222
/// By default, `HashMap` uses a hashing algorithm selected to provide
2323
/// resistance against HashDoS attacks. The algorithm is randomly seeded, and a
@@ -62,6 +62,7 @@ use crate::sys;
6262
/// The original C++ version of SwissTable can be found [here], and this
6363
/// [CppCon talk] gives an overview of how the algorithm works.
6464
///
65+
/// [hash map]: crate::collections#use-a-hashmap-when
6566
/// [hashing algorithms available on crates.io]: https://crates.io/keywords/hasher
6667
/// [SwissTable]: https://abseil.io/blog/20180927-swisstables
6768
/// [here]: https://github.com/abseil/abseil-cpp/blob/master/absl/container/internal/raw_hash_set.h

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use super::map::{map_try_reserve_error, RandomState};
1919
// for `bucket.val` in the case of HashSet. I suppose we would need HKT
2020
// to get rid of it properly.
2121

22-
/// A hash set implemented as a `HashMap` where the value is `()`.
22+
/// A [hash set] implemented as a `HashMap` where the value is `()`.
2323
///
2424
/// As with the [`HashMap`] type, a `HashSet` requires that the elements
2525
/// implement the [`Eq`] and [`Hash`] traits. This can frequently be achieved by
@@ -105,6 +105,7 @@ use super::map::{map_try_reserve_error, RandomState};
105105
/// // use the values stored in the set
106106
/// ```
107107
///
108+
/// [hash set]: crate::collections#use-the-set-variant-of-any-of-these-maps-when
108109
/// [`HashMap`]: crate::collections::HashMap
109110
/// [`RefCell`]: crate::cell::RefCell
110111
/// [`Cell`]: crate::cell::Cell

0 commit comments

Comments
 (0)