extra: Add with_capacity to PriorityQueue and SmallIntMap
This commit is contained in:
parent
8057faa2d3
commit
58ac1c3563
@ -117,6 +117,11 @@ impl<T:Ord> PriorityQueue<T> {
|
||||
/// Create an empty PriorityQueue
|
||||
pub fn new() -> PriorityQueue<T> { PriorityQueue{data: ~[],} }
|
||||
|
||||
/// Create an empty PriorityQueue with capacity `capacity`
|
||||
pub fn with_capacity(capacity: uint) -> PriorityQueue<T> {
|
||||
PriorityQueue { data: slice::with_capacity(capacity) }
|
||||
}
|
||||
|
||||
/// Create a PriorityQueue from a vector (heapify)
|
||||
pub fn from_vec(xs: ~[T]) -> PriorityQueue<T> {
|
||||
let mut q = PriorityQueue{data: xs,};
|
||||
|
@ -112,6 +112,11 @@ impl<V> SmallIntMap<V> {
|
||||
/// Create an empty SmallIntMap
|
||||
pub fn new() -> SmallIntMap<V> { SmallIntMap{v: ~[]} }
|
||||
|
||||
/// Create an empty SmallIntMap with capacity `capacity`
|
||||
pub fn with_capacity(capacity: uint) -> SmallIntMap<V> {
|
||||
SmallIntMap { v: slice::with_capacity(capacity) }
|
||||
}
|
||||
|
||||
pub fn get<'a>(&'a self, key: &uint) -> &'a V {
|
||||
self.find(key).expect("key not present")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user