Skip to content

Commit e394bb7

Browse files
committed
BTree: refine some comments
1 parent 23461b2 commit e394bb7

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ mod entry;
1717
pub use entry::{Entry, OccupiedEntry, OccupiedError, VacantEntry};
1818
use Entry::*;
1919

20-
/// Minimum number of elements in nodes that are not a root.
20+
/// Minimum number of elements in a node that is not a root.
2121
/// We might temporarily have fewer elements during methods.
2222
pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT;
2323

2424
// 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).
26-
// - If the root node is internal, it must contain at least 1 element.
26+
// - Every non-leaf node contains at least 1 element (has at least 2 children).
2727
// - Every non-root node contains at least MIN_LEN elements.
2828
//
29-
// An empty map may be represented both by the absence of a root node or by a
29+
// An empty map is represented either by the absence of a root node or by a
3030
// root node that is an empty leaf.
3131

3232
/// A map based on a [B-Tree].
@@ -1723,8 +1723,8 @@ impl<'a, K: 'a, V: 'a> DrainFilterInner<'a, K, V> {
17231723
pub(super) fn size_hint(&self) -> (usize, Option<usize>) {
17241724
// In most of the btree iterators, `self.length` is the number of elements
17251725
// yet to be visited. Here, it includes elements that were visited and that
1726-
// the predicate decided not to drain. Making this upper bound more accurate
1727-
// requires maintaining an extra field and is not worth while.
1726+
// the predicate decided not to drain. Making this upper bound more tight
1727+
// during iteration would require an extra field.
17281728
(0, Some(*self.length))
17291729
}
17301730
}

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

+2-4
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,7 @@ impl<K, V> Handle<NodeRef<marker::Dying, K, V, marker::Leaf>, marker::Edge> {
440440
/// - The given edge must not have been previously returned by counterpart
441441
/// `deallocating_next_back`.
442442
/// - The returned KV handle is only valid to access the key and value,
443-
/// and only valid until the next call to this method or counterpart
444-
/// `deallocating_next_back`.
443+
/// and only valid until the next call to a `deallocating_` method.
445444
unsafe fn deallocating_next(
446445
self,
447446
) -> Option<(Self, Handle<NodeRef<marker::Dying, K, V, marker::LeafOrInternal>, marker::KV>)>
@@ -470,8 +469,7 @@ impl<K, V> Handle<NodeRef<marker::Dying, K, V, marker::Leaf>, marker::Edge> {
470469
/// - The given edge must not have been previously returned by counterpart
471470
/// `deallocating_next`.
472471
/// - The returned KV handle is only valid to access the key and value,
473-
/// and only valid until the next call to this method or counterpart
474-
/// `deallocating_next`.
472+
/// and only valid until the next call to a `deallocating_` method.
475473
unsafe fn deallocating_next_back(
476474
self,
477475
) -> Option<(Self, Handle<NodeRef<marker::Dying, K, V, marker::LeafOrInternal>, marker::KV>)>

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ impl<K, V> NodeRef<marker::Owned, K, V, marker::LeafOrInternal> {
574574
/// no cleanup is done on any of the keys, values and other children.
575575
/// This decreases the height by 1 and is the opposite of `push_internal_level`.
576576
///
577-
/// Requires exclusive access to the `Root` object but not to the root node;
577+
/// Requires exclusive access to the `NodeRef` object but not to the root node;
578578
/// it will not invalidate other handles or references to the root node.
579579
///
580580
/// Panics if there is no internal level, i.e., if the root node is a leaf.
@@ -1663,7 +1663,7 @@ pub mod marker {
16631663
const PERMITS_TRAVERSAL: bool = true;
16641664
}
16651665
impl BorrowType for Owned {
1666-
// Traversal isn't needede, it happens using the result of `borrow_mut`.
1666+
// Traversal isn't needed, it happens using the result of `borrow_mut`.
16671667
// By disabling traversal, and only creating new references to roots,
16681668
// we know that every reference of the `Owned` type is to a root node.
16691669
const PERMITS_TRAVERSAL: bool = false;

0 commit comments

Comments
 (0)