From d3ea28992194484dea671a19b808b62ed8efd5d1 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 23 Jun 2023 12:26:51 -0700 Subject: [PATCH] Document the lower-bound semantics of capacity --- src/map.rs | 5 +++++ src/set.rs | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/map.rs b/src/map.rs index cd03ae8a..cb405caf 100644 --- a/src/map.rs +++ b/src/map.rs @@ -197,6 +197,11 @@ impl IndexMap { } } + /// 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() diff --git a/src/set.rs b/src/set.rs index 8e107594..dbee481f 100644 --- a/src/set.rs +++ b/src/set.rs @@ -176,6 +176,11 @@ impl IndexSet { } } + /// 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()