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
use super::*;
pub trait LastInFirstOutQueue<B: LastInFirstOutBucket>: Queue<B> {
fn push(&mut self, item: B::Item, priority: usize) {
self.bucket_for_adding(priority).push(item);
}
fn pop(&mut self, priority: usize) -> Option<B::Item> {
self.bucket_for_removing(priority)?.pop()
}
fn pop_min(&mut self) -> Option<B::Item> {
self.pop(self.min_priority()?)
}
fn pop_max(&mut self) -> Option<B::Item> {
self.pop(self.max_priority()?)
}
}
impl<B: LastInFirstOutBucket> LastInFirstOutQueue<B> for BucketQueue<B> { }
impl<'a, Q, B, C> LastInFirstOutQueue<C> for DeferredBucket<'a, Q, B>
where Q: Queue<B>,
B: Bucket + Queue<C>,
C: LastInFirstOutBucket,
{ }