1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use super::*;
pub trait DoubleEndedQueue<B: DoubleEndedBucket>: Queue<B> {
fn push_back(&mut self, item: B::Item, priority: usize) {
self.bucket_for_adding(priority).push_back(item);
}
fn push_front(&mut self, item: B::Item, priority: usize) {
self.bucket_for_adding(priority).push_front(item);
}
fn pop_back(&mut self, priority: usize) -> Option<B::Item> {
self.bucket_for_removing(priority)?.pop_back()
}
fn pop_front(&mut self, priority: usize) -> Option<B::Item> {
self.bucket_for_removing(priority)?.pop_front()
}
fn pop_back_min(&mut self) -> Option<B::Item> {
self.pop_back(self.min_priority()?)
}
fn pop_front_min(&mut self) -> Option<B::Item> {
self.pop_front(self.min_priority()?)
}
fn pop_back_max(&mut self) -> Option<B::Item> {
self.pop_back(self.max_priority()?)
}
fn pop_front_max(&mut self) -> Option<B::Item> {
self.pop_front(self.max_priority()?)
}
}
impl<B: DoubleEndedBucket> DoubleEndedQueue<B> for BucketQueue<B> { }
impl<'a, Q, B, C> DoubleEndedQueue<C> for DeferredBucket<'a, Q, B>
where Q: Queue<B>,
B: Bucket + Queue<C>,
C: DoubleEndedBucket,
{ }