diff options
| author | Daniel Micay <danielmicay@gmail.com> | 2013-01-21 21:59:19 -0500 |
|---|---|---|
| committer | Daniel Micay <danielmicay@gmail.com> | 2013-01-22 08:10:08 -0500 |
| commit | 6f4d86ed904ed7ae04edc4226a0a1c2d39067d57 (patch) | |
| tree | 3f29d860792467b38ec0e3f3eee987a804da0d3a /src/libstd/priority_queue.rs | |
| parent | d635a6e506012ad4d427578e394aa2041e7dbdfb (diff) | |
| download | rust-6f4d86ed904ed7ae04edc4226a0a1c2d39067d57.tar.gz rust-6f4d86ed904ed7ae04edc4226a0a1c2d39067d57.zip | |
add a base Container trait
Diffstat (limited to 'src/libstd/priority_queue.rs')
| -rw-r--r-- | src/libstd/priority_queue.rs | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/libstd/priority_queue.rs b/src/libstd/priority_queue.rs index 0ff40b6421a..ee78fafb60b 100644 --- a/src/libstd/priority_queue.rs +++ b/src/libstd/priority_queue.rs @@ -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() } |
