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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
pub trait PartialOrder : Eq {
fn less_than(&self, other: &Self) -> bool {
self.less_equal(other) && self != other
}
fn less_equal(&self, other: &Self) -> bool;
}
pub trait TotalOrder : PartialOrder { }
macro_rules! implement_partial {
($($index_type:ty,)*) => (
$(
impl PartialOrder for $index_type {
#[inline(always)] fn less_than(&self, other: &Self) -> bool { self < other }
#[inline(always)] fn less_equal(&self, other: &Self) -> bool { self <= other }
}
)*
)
}
macro_rules! implement_total {
($($index_type:ty,)*) => (
$(
impl TotalOrder for $index_type { }
)*
)
}
implement_partial!(u8, u16, u32, u64, usize, i8, i16, i32, i64, isize, (), ::std::time::Duration,);
implement_total!(u8, u16, u32, u64, usize, i8, i16, i32, i64, isize, (), ::std::time::Duration,);
use std::fmt::{Formatter, Error, Debug};
use crate::progress::Timestamp;
use crate::progress::timestamp::Refines;
impl<TOuter: Timestamp, TInner: Timestamp> Refines<TOuter> for Product<TOuter, TInner> {
fn to_inner(other: TOuter) -> Self {
Product::new(other, Default::default())
}
fn to_outer(self: Product<TOuter, TInner>) -> TOuter {
self.outer
}
fn summarize(path: <Self as Timestamp>::Summary) -> <TOuter as Timestamp>::Summary {
path.outer
}
}
#[derive(Abomonation, Copy, Clone, Hash, Eq, PartialEq, Default, Ord, PartialOrd, Serialize, Deserialize)]
pub struct Product<TOuter, TInner> {
pub outer: TOuter,
pub inner: TInner,
}
impl<TOuter, TInner> Product<TOuter, TInner> {
pub fn new(outer: TOuter, inner: TInner) -> Product<TOuter, TInner> {
Product {
outer,
inner,
}
}
}
impl<TOuter: Debug, TInner: Debug> Debug for Product<TOuter, TInner> {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
f.write_str(&format!("({:?}, {:?})", self.outer, self.inner))
}
}
impl<TOuter: PartialOrder, TInner: PartialOrder> PartialOrder for Product<TOuter, TInner> {
#[inline(always)]
fn less_equal(&self, other: &Self) -> bool {
self.outer.less_equal(&other.outer) && self.inner.less_equal(&other.inner)
}
}
impl<TOuter: Timestamp, TInner: Timestamp> Timestamp for Product<TOuter, TInner> {
type Summary = Product<TOuter::Summary, TInner::Summary>;
}
use crate::progress::timestamp::PathSummary;
impl<TOuter: Timestamp, TInner: Timestamp> PathSummary<Product<TOuter, TInner>> for Product<TOuter::Summary, TInner::Summary> {
#[inline]
fn results_in(&self, product: &Product<TOuter, TInner>) -> Option<Product<TOuter, TInner>> {
self.outer.results_in(&product.outer)
.and_then(|outer|
self.inner.results_in(&product.inner)
.map(|inner| Product::new(outer, inner))
)
}
#[inline]
fn followed_by(&self, other: &Product<TOuter::Summary, TInner::Summary>) -> Option<Product<TOuter::Summary, TInner::Summary>> {
self.outer.followed_by(&other.outer)
.and_then(|outer|
self.inner.followed_by(&other.inner)
.map(|inner| Product::new(outer, inner))
)
}
}
pub trait Empty : PartialOrder { }
impl Empty for () { }
impl<T1: Empty, T2: Empty> Empty for Product<T1, T2> { }
impl<T1, T2> TotalOrder for Product<T1, T2> where T1: Empty, T2: TotalOrder { }