From 58ac1c3563679b51f0e6dae1188cb635f1e89292 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Thu, 3 Apr 2014 20:47:53 -0700 Subject: [PATCH] extra: Add with_capacity to PriorityQueue and SmallIntMap --- src/libcollections/priority_queue.rs | 5 +++++ src/libcollections/smallintmap.rs | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/libcollections/priority_queue.rs b/src/libcollections/priority_queue.rs index 8c7eb1c6033..a13785104ab 100644 --- a/src/libcollections/priority_queue.rs +++ b/src/libcollections/priority_queue.rs @@ -117,6 +117,11 @@ impl PriorityQueue { /// Create an empty PriorityQueue pub fn new() -> PriorityQueue { PriorityQueue{data: ~[],} } + /// Create an empty PriorityQueue with capacity `capacity` + pub fn with_capacity(capacity: uint) -> PriorityQueue { + PriorityQueue { data: slice::with_capacity(capacity) } + } + /// Create a PriorityQueue from a vector (heapify) pub fn from_vec(xs: ~[T]) -> PriorityQueue { let mut q = PriorityQueue{data: xs,}; diff --git a/src/libcollections/smallintmap.rs b/src/libcollections/smallintmap.rs index db7fafe522b..bd4f85aa81a 100644 --- a/src/libcollections/smallintmap.rs +++ b/src/libcollections/smallintmap.rs @@ -112,6 +112,11 @@ impl SmallIntMap { /// Create an empty SmallIntMap pub fn new() -> SmallIntMap { SmallIntMap{v: ~[]} } + /// Create an empty SmallIntMap with capacity `capacity` + pub fn with_capacity(capacity: uint) -> SmallIntMap { + SmallIntMap { v: slice::with_capacity(capacity) } + } + pub fn get<'a>(&'a self, key: &uint) -> &'a V { self.find(key).expect("key not present") }