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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
use std::default::Default;
use std::fmt::{Display, Formatter};
use std::fmt::Error;
use order::PartialOrder;
use progress::{Timestamp, PathSummary};
use progress::nested::product::Product;
use progress::nested::summary::Summary::{Local, Outer};
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub enum Summary<S, T> {
Local(T),
Outer(S, T),
}
impl<S, T: Default> Default for Summary<S, T> {
fn default() -> Summary<S, T> { Local(Default::default()) }
}
impl<S: PartialOrder, T: PartialOrder> PartialOrder for Summary<S, T> {
#[inline(always)]
fn less_equal(&self, other: &Self) -> bool {
match (self, other) {
(&Local(ref t1), &Local(ref t2)) => t1.less_equal(t2),
(&Outer(ref s1, ref t1), &Outer(ref s2, ref t2)) => s1.less_equal(s2) && t1.less_equal(t2),
_ => false
}
}
}
impl<TOuter, SOuter, TInner, SInner> PathSummary<Product<TOuter, TInner>> for Summary<SOuter, SInner>
where TOuter: Timestamp,
TInner: Timestamp,
SOuter: PathSummary<TOuter>,
SInner: PathSummary<TInner>,
{
#[inline]
fn results_in(&self, product: &Product<TOuter, TInner>) -> Option<Product<TOuter, TInner>> {
match *self {
Local(ref iters) => iters.results_in(&product.inner).map(|x| Product::new(product.outer.clone(), x)),
Outer(ref summary, ref iters) => summary.results_in(&product.outer).map(|x| Product::new(x, iters.results_in(&Default::default()).unwrap())),
}
}
#[inline]
fn followed_by(&self, other: &Summary<SOuter, SInner>) -> Option<Summary<SOuter, SInner>> {
match (self, other) {
(&Local(ref inner1), &Local(ref inner2)) => inner1.followed_by(inner2).map(|x| Local(x)),
(&Local(_), &Outer(_, _)) => Some(other.clone()),
(&Outer(ref outer1, ref inner1), &Local(ref inner2)) => inner1.followed_by(inner2).map(|x| Outer(outer1.clone(), x)),
(&Outer(ref outer1, _), &Outer(ref outer2, ref inner2)) => outer1.followed_by(outer2).map(|x| Outer(x, inner2.clone())),
}
}
}
impl<SOuter: Display, SInner: Display> Display for Summary<SOuter, SInner> {
#[inline]
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
match *self {
Local(ref s) => write!(f, "Local({})", s),
Outer(ref s, ref t) => write!(f, "Outer({}, {})", s, t)
}
}
}