about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCorey Richardson <corey@octayn.net>2014-12-05 10:08:24 -0800
committerCorey Richardson <corey@octayn.net>2014-12-05 10:08:24 -0800
commitd602c058aefc370e33e5aa3e0b0f0819f8f01e71 (patch)
treeac4a6b98b821144cf308eba32b9a1794c46cec0c
parent39646d2ff6a127f7e6b19917930b9771a4ad1c54 (diff)
parent0d3c41561751bbcbc8f2fccf7369280e35dbb68f (diff)
downloadrust-d602c058aefc370e33e5aa3e0b0f0819f8f01e71.tar.gz
rust-d602c058aefc370e33e5aa3e0b0f0819f8f01e71.zip
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`)
-rw-r--r--src/libcollections/vec_map.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/libcollections/vec_map.rs b/src/libcollections/vec_map.rs
index 36e66ed27f3..986e7ef5bc2 100644
--- a/src/libcollections/vec_map.rs
+++ b/src/libcollections/vec_map.rs
@@ -115,6 +115,22 @@ impl<V> VecMap<V> {
         VecMap { v: Vec::with_capacity(capacity) }
     }
 
+    /// Returns the number of elements the `VecMap` can hold without
+    /// reallocating.
+    ///
+    /// # Example
+    ///
+    /// ```
+    /// use std::collections::VecMap;
+    /// let map: VecMap<String> = VecMap::with_capacity(10);
+    /// assert!(map.capacity() >= 10);
+    /// ```
+    #[inline]
+    #[unstable = "matches collection reform specification, waiting for dust to settle"]
+    pub fn capacity(&self) -> uint {
+        self.v.capacity()
+    }
+
     /// Returns an iterator visiting all keys in ascending order by the keys.
     /// The iterator's element type is `uint`.
     #[unstable = "matches collection reform specification, waiting for dust to settle"]