Skip to content

Commit d602c05

Browse files
committed
rollup merge of #19528: aliblong/add_vecmap_capacity
Part of #18424 Adds `capacity()` function to VecMap, as per the collections reform. (Salvaged from #19516, #19523, while we await an RFC regarding `reserve`/`reserve_index` for `VecMap`)
2 parents 39646d2 + 0d3c415 commit d602c05

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/libcollections/vec_map.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,22 @@ impl<V> VecMap<V> {
115115
VecMap { v: Vec::with_capacity(capacity) }
116116
}
117117

118+
/// Returns the number of elements the `VecMap` can hold without
119+
/// reallocating.
120+
///
121+
/// # Example
122+
///
123+
/// ```
124+
/// use std::collections::VecMap;
125+
/// let map: VecMap<String> = VecMap::with_capacity(10);
126+
/// assert!(map.capacity() >= 10);
127+
/// ```
128+
#[inline]
129+
#[unstable = "matches collection reform specification, waiting for dust to settle"]
130+
pub fn capacity(&self) -> uint {
131+
self.v.capacity()
132+
}
133+
118134
/// Returns an iterator visiting all keys in ascending order by the keys.
119135
/// The iterator's element type is `uint`.
120136
#[unstable = "matches collection reform specification, waiting for dust to settle"]

0 commit comments

Comments
 (0)