Skip to content

Commit

Permalink
Document the lower-bound semantics of capacity
Browse files Browse the repository at this point in the history
  • Loading branch information
cuviper committed Jun 23, 2023
1 parent 74e14da commit d3ea289
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ impl<K, V, S> IndexMap<K, V, S> {
}
}

/// Return the number of elements the map can hold without reallocating.
///
/// This number is a lower bound; the map might be able to hold more,
/// but is guaranteed to be able to hold at least this many.
///
/// Computes in **O(1)** time.
pub fn capacity(&self) -> usize {
self.core.capacity()
Expand Down
5 changes: 5 additions & 0 deletions src/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ impl<T, S> IndexSet<T, S> {
}
}

/// Return the number of elements the set can hold without reallocating.
///
/// This number is a lower bound; the set might be able to hold more,
/// but is guaranteed to be able to hold at least this many.
///
/// Computes in **O(1)** time.
pub fn capacity(&self) -> usize {
self.map.capacity()
Expand Down

0 comments on commit d3ea289

Please sign in to comment.