declarative_dataflow/timestamp/
pair.rs1#[derive(Hash, Default, Clone, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)]
14pub struct Pair<S, T> {
15 pub first: S,
17 pub second: T,
19}
20
21impl<S, T> Pair<S, T> {
22 pub fn new(first: S, second: T) -> Self {
24 Pair { first, second }
25 }
26}
27
28use timely::order::PartialOrder;
30impl<S: PartialOrder, T: PartialOrder> PartialOrder for Pair<S, T> {
31 fn less_equal(&self, other: &Self) -> bool {
32 self.first.less_equal(&other.first) && self.second.less_equal(&other.second)
33 }
34}
35
36use timely::progress::timestamp::Refines;
37impl<S: Timestamp, T: Timestamp> Refines<()> for Pair<S, T> {
38 fn to_inner(_outer: ()) -> Self {
39 Default::default()
40 }
41 fn to_outer(self) {}
42 fn summarize(_summary: <Self>::Summary) {}
43}
44
45use timely::progress::PathSummary;
48
49impl<S: Timestamp, T: Timestamp> PathSummary<Pair<S, T>> for () {
50 fn results_in(&self, timestamp: &Pair<S, T>) -> Option<Pair<S, T>> {
51 Some(timestamp.clone())
52 }
53 fn followed_by(&self, other: &Self) -> Option<Self> {
54 Some(other.clone())
55 }
56}
57
58use timely::progress::Timestamp;
60impl<S: Timestamp, T: Timestamp> Timestamp for Pair<S, T> {
61 type Summary = ();
62}
63
64use differential_dataflow::lattice::Lattice;
67impl<S: Lattice, T: Lattice> Lattice for Pair<S, T> {
68 fn minimum() -> Self {
69 Pair {
70 first: S::minimum(),
71 second: T::minimum(),
72 }
73 }
74 fn join(&self, other: &Self) -> Self {
75 Pair {
76 first: self.first.join(&other.first),
77 second: self.second.join(&other.second),
78 }
79 }
80 fn meet(&self, other: &Self) -> Self {
81 Pair {
82 first: self.first.meet(&other.first),
83 second: self.second.meet(&other.second),
84 }
85 }
86}
87
88use std::fmt::{Debug, Error, Formatter};
89
90impl<TOuter: Debug, TInner: Debug> Debug for Pair<TOuter, TInner> {
92 fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
93 f.write_str(&format!("({:?}, {:?})", self.first, self.second))
94 }
95}
96
97impl<TOuter, TInner> std::ops::Sub for Pair<TOuter, TInner>
98where
99 TOuter: std::ops::Sub<Output = TOuter>,
100 TInner: std::ops::Sub<Output = TInner>,
101{
102 type Output = Self;
103
104 fn sub(self, other: Self) -> Self {
105 Pair {
106 first: self.first.sub(other.first),
107 second: self.second.sub(other.second),
108 }
109 }
110}