1
Fork 0

add a base Container trait

This commit is contained in:
Daniel Micay 2013-01-21 21:59:19 -05:00
parent d635a6e506
commit 6f4d86ed90
4 changed files with 46 additions and 36 deletions

View file

@ -10,7 +10,7 @@
//! A priority queue implemented with a binary heap
use core::container::Mutable;
use core::container::{Container, Mutable};
use core::cmp::Ord;
use core::prelude::*;
use core::ptr::addr_of;
@ -25,6 +25,14 @@ pub struct PriorityQueue <T: Ord>{
priv data: ~[T],
}
impl <T: Ord> PriorityQueue<T>: Container {
/// Returns the length of the queue
pure fn len(&self) -> uint { self.data.len() }
/// Returns true if a queue contains no elements
pure fn is_empty(&self) -> bool { self.data.is_empty() }
}
impl <T: Ord> PriorityQueue<T>: Mutable {
/// Drop all items from the queue
fn clear(&mut self) { self.data.truncate(0) }
@ -39,12 +47,6 @@ impl <T: Ord> PriorityQueue<T> {
if self.is_empty() { None } else { Some(self.top()) }
}
/// Returns the length of the queue
pure fn len(&self) -> uint { self.data.len() }
/// Returns true if a queue contains no elements
pure fn is_empty(&self) -> bool { self.data.is_empty() }
/// Returns true if a queue contains some elements
pure fn is_not_empty(&self) -> bool { self.data.is_not_empty() }