Skip to content

Commit 366f97b

Browse files
authored
Rollup merge of #81082 - ssomers:btree_cleanup_comments, r=Mark-Simulacrum
BTreeMap: clean up a few more comments And mark `pop` as unsafe. r? ```@Mark-Simulacrum```
2 parents 19370a4 + 50ee0b2 commit 366f97b

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ impl<K, V> NodeRef<marker::Owned, K, V, marker::LeafOrInternal> {
184184

185185
/// Removes the internal root node, using its first child as the new root node.
186186
/// As it is intended only to be called when the root node has only one child,
187-
/// no cleanup is done on any of the other children.
187+
/// no cleanup is done on any of the keys, values and other children.
188188
/// This decreases the height by 1 and is the opposite of `push_internal_level`.
189189
///
190190
/// Requires exclusive access to the `Root` object but not to the root node;
@@ -225,7 +225,7 @@ impl<K, V> NodeRef<marker::Owned, K, V, marker::LeafOrInternal> {
225225
/// - When this is `Owned`, the `NodeRef` acts roughly like `Box<Node>`,
226226
/// but does not have a destructor, and must be cleaned up manually.
227227
/// Since any `NodeRef` allows navigating through the tree, `BorrowType`
228-
/// effectively applies to the entire tree, not just the node itself.
228+
/// effectively applies to the entire tree, not just to the node itself.
229229
/// - `K` and `V`: These are the types of keys and values stored in the nodes.
230230
/// - `Type`: This can be `Leaf`, `Internal`, or `LeafOrInternal`. When this is
231231
/// `Leaf`, the `NodeRef` points to a leaf node, when this is `Internal` the
@@ -425,7 +425,7 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Immut<'a>, K, V, Type> {
425425

426426
impl<K, V> NodeRef<marker::Owned, K, V, marker::LeafOrInternal> {
427427
/// Similar to `ascend`, gets a reference to a node's parent node, but also
428-
/// deallocate the current node in the process. This is unsafe because the
428+
/// deallocates the current node in the process. This is unsafe because the
429429
/// current node will still be accessible despite being deallocated.
430430
pub unsafe fn deallocate_and_ascend(
431431
self,
@@ -661,7 +661,10 @@ impl<'a, K: 'a, V: 'a> NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal> {
661661
/// Removes a key-value pair from the end of the node and returns the pair.
662662
/// Also removes the edge that was to the right of that pair and, if the node
663663
/// is internal, returns the orphaned subtree that this edge owned.
664-
fn pop(&mut self) -> (K, V, Option<Root<K, V>>) {
664+
///
665+
/// # Safety
666+
/// The node must not be empty.
667+
unsafe fn pop(&mut self) -> (K, V, Option<Root<K, V>>) {
665668
debug_assert!(self.len() > 0);
666669

667670
let idx = self.len() - 1;

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ pub enum SearchResult<BorrowType, K, V, FoundType, GoDownType> {
1212

1313
/// Looks up a given key in a (sub)tree headed by the given node, recursively.
1414
/// Returns a `Found` with the handle of the matching KV, if any. Otherwise,
15-
/// returns a `GoDown` with the handle of the possible leaf edge where the key
16-
/// belongs.
15+
/// returns a `GoDown` with the handle of the leaf edge where the key belongs.
1716
///
1817
/// The result is meaningful only if the tree is ordered by key, like the tree
1918
/// in a `BTreeMap` is.

0 commit comments

Comments
 (0)