Skip to content

Commit

Permalink
Merge pull request #266 from cuviper/doc-capacity
Browse files Browse the repository at this point in the history
Document the lower-bound semantics of capacity
  • Loading branch information
cuviper authored Jun 23, 2023
2 parents 74e14da + d3ea289 commit b5b2814
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 b5b2814

Please sign in to comment.