@@ -31,7 +31,7 @@ use std::collections::hash_map::RandomState;
3131use self :: core:: IndexMapCore ;
3232use crate :: equivalent:: Equivalent ;
3333use crate :: util:: { third, try_simplify_range} ;
34- use crate :: { Bucket , Entries , HashValue } ;
34+ use crate :: { Bucket , Entries , HashValue , TryReserveError } ;
3535
3636/// A hash table where the iteration order of the key-value pairs is independent
3737/// of the hash values of the keys.
@@ -319,6 +319,37 @@ where
319319 self . core . reserve ( additional) ;
320320 }
321321
322+ /// Reserve capacity for `additional` more key-value pairs, without over-allocating.
323+ ///
324+ /// Unlike `reserve`, this does not deliberately over-allocate the entry capacity to avoid
325+ /// frequent re-allocations. However, the underlying data structures may still have internal
326+ /// capacity requirements, and the allocator itself may give more space than requested, so this
327+ /// cannot be relied upon to be precisely minimal.
328+ ///
329+ /// Computes in **O(n)** time.
330+ pub fn reserve_exact ( & mut self , additional : usize ) {
331+ self . core . reserve_exact ( additional) ;
332+ }
333+
334+ /// Try to reserve capacity for `additional` more key-value pairs.
335+ ///
336+ /// Computes in **O(n)** time.
337+ pub fn try_reserve ( & mut self , additional : usize ) -> Result < ( ) , TryReserveError > {
338+ self . core . try_reserve ( additional)
339+ }
340+
341+ /// Try to reserve capacity for `additional` more key-value pairs, without over-allocating.
342+ ///
343+ /// Unlike `try_reserve`, this does not deliberately over-allocate the entry capacity to avoid
344+ /// frequent re-allocations. However, the underlying data structures may still have internal
345+ /// capacity requirements, and the allocator itself may give more space than requested, so this
346+ /// cannot be relied upon to be precisely minimal.
347+ ///
348+ /// Computes in **O(n)** time.
349+ pub fn try_reserve_exact ( & mut self , additional : usize ) -> Result < ( ) , TryReserveError > {
350+ self . core . try_reserve_exact ( additional)
351+ }
352+
322353 /// Shrink the capacity of the map as much as possible.
323354 ///
324355 /// Computes in **O(n)** time.
0 commit comments