Implement PrimaryMap::with_capacity.

This commit is contained in:
Dan Gohman
2018-11-30 16:59:35 -08:00
parent 6e17bebf44
commit 42e35c4c57

View File

@@ -41,6 +41,14 @@ where
}
}
/// Create a new empty map with the given capacity.
pub fn with_capacity(capacity: usize) -> Self {
Self {
elems: Vec::with_capacity(capacity),
unused: PhantomData,
}
}
/// Check if `k` is a valid key in the map.
pub fn is_valid(&self, k: K) -> bool {
k.index() < self.elems.len()