Skip to content

Commit b846f73

Browse files
authored
Merge batcher for flat container without key and value (#547)
Signed-off-by: Moritz Hoffmann <[email protected]>
1 parent dafe288 commit b846f73

File tree

1 file changed

+21
-26
lines changed

1 file changed

+21
-26
lines changed

src/trace/implementations/merge_batcher_flat.rs

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::marker::PhantomData;
55
use timely::progress::frontier::{Antichain, AntichainRef};
66
use timely::{Data, PartialOrder};
77
use timely::container::flatcontainer::{Push, FlatStack, Region, ReserveItems};
8-
use timely::container::flatcontainer::impls::tuple::{TupleABCRegion, TupleABRegion};
8+
use timely::container::flatcontainer::impls::tuple::TupleABCRegion;
99

1010
use crate::difference::{IsZero, Semigroup};
1111
use crate::trace::implementations::merge_batcher::Merger;
@@ -56,10 +56,8 @@ impl<MC: Region> FlatcontainerMerger<MC> {
5656

5757
/// Behavior to dissect items of chunks in the merge batcher
5858
pub trait MergerChunk: Region {
59-
/// The key of the update
60-
type Key<'a>: Ord where Self: 'a;
61-
/// The value of the update
62-
type Val<'a>: Ord where Self: 'a;
59+
/// The data portion of the update
60+
type Data<'a>: Ord where Self: 'a;
6361
/// The time of the update
6462
type Time<'a>: Ord where Self: 'a;
6563
/// The owned time type.
@@ -70,28 +68,25 @@ pub trait MergerChunk: Region {
7068
type DiffOwned;
7169

7270
/// Split a read item into its constituents. Must be cheap.
73-
fn into_parts<'a>(item: Self::ReadItem<'a>) -> (Self::Key<'a>, Self::Val<'a>, Self::Time<'a>, Self::Diff<'a>);
71+
fn into_parts<'a>(item: Self::ReadItem<'a>) -> (Self::Data<'a>, Self::Time<'a>, Self::Diff<'a>);
7472
}
7573

76-
impl<K,V,T,R> MergerChunk for TupleABCRegion<TupleABRegion<K, V>, T, R>
74+
impl<D,T,R> MergerChunk for TupleABCRegion<D, T, R>
7775
where
78-
K: Region,
79-
for<'a> K::ReadItem<'a>: Ord,
80-
V: Region,
81-
for<'a> V::ReadItem<'a>: Ord,
76+
D: Region,
77+
for<'a> D::ReadItem<'a>: Ord,
8278
T: Region,
8379
for<'a> T::ReadItem<'a>: Ord,
8480
R: Region,
8581
{
86-
type Key<'a> = K::ReadItem<'a> where Self: 'a;
87-
type Val<'a> = V::ReadItem<'a> where Self: 'a;
82+
type Data<'a> = D::ReadItem<'a> where Self: 'a;
8883
type Time<'a> = T::ReadItem<'a> where Self: 'a;
8984
type TimeOwned = T::Owned;
9085
type Diff<'a> = R::ReadItem<'a> where Self: 'a;
9186
type DiffOwned = R::Owned;
9287

93-
fn into_parts<'a>(((key, val), time, diff): Self::ReadItem<'a>) -> (Self::Key<'a>, Self::Val<'a>, Self::Time<'a>, Self::Diff<'a>) {
94-
(key, val, time, diff)
88+
fn into_parts<'a>((data, time, diff): Self::ReadItem<'a>) -> (Self::Data<'a>, Self::Time<'a>, Self::Diff<'a>) {
89+
(data, time, diff)
9590
}
9691
}
9792

@@ -100,8 +95,8 @@ where
10095
for<'a> MC: MergerChunk + Clone + 'static
10196
+ ReserveItems<<MC as Region>::ReadItem<'a>>
10297
+ Push<<MC as Region>::ReadItem<'a>>
103-
+ Push<((MC::Key<'a>, MC::Val<'a>), MC::Time<'a>, &'a MC::DiffOwned)>
104-
+ Push<((MC::Key<'a>, MC::Val<'a>), MC::Time<'a>, MC::Diff<'a>)>,
98+
+ Push<(MC::Data<'a>, MC::Time<'a>, &'a MC::DiffOwned)>
99+
+ Push<(MC::Data<'a>, MC::Time<'a>, MC::Diff<'a>)>,
105100
for<'a> MC::Time<'a>: PartialOrder<MC::TimeOwned> + Copy + IntoOwned<'a, Owned=MC::TimeOwned>,
106101
for<'a> MC::Diff<'a>: IntoOwned<'a, Owned = MC::DiffOwned>,
107102
for<'a> MC::TimeOwned: Ord + PartialOrder + PartialOrder<MC::Time<'a>> + Data,
@@ -125,9 +120,9 @@ where
125120
while !head1.is_empty() && !head2.is_empty() {
126121
while (result.capacity() - result.len()) > 0 && !head1.is_empty() && !head2.is_empty() {
127122
let cmp = {
128-
let (key1, val1, time1, _diff) = MC::into_parts(head1.peek());
129-
let (key2, val2, time2, _diff) = MC::into_parts(head2.peek());
130-
((key1, val1), time1).cmp(&((key2, val2), time2))
123+
let (data1, time1, _diff) = MC::into_parts(head1.peek());
124+
let (data2, time2, _diff) = MC::into_parts(head2.peek());
125+
(data1, time1).cmp(&(data2, time2))
131126
};
132127
// TODO: The following less/greater branches could plausibly be a good moment for
133128
// `copy_range`, on account of runs of records that might benefit more from a
@@ -140,12 +135,12 @@ where
140135
result.copy(head2.pop());
141136
}
142137
Ordering::Equal => {
143-
let (key, val, time1, diff1) = MC::into_parts(head1.pop());
144-
let (_key, _val, _time2, diff2) = MC::into_parts(head2.pop());
138+
let (data, time1, diff1) = MC::into_parts(head1.pop());
139+
let (_data, _time2, diff2) = MC::into_parts(head2.pop());
145140
diff1.clone_onto(&mut diff);
146141
diff.plus_equals(&diff2);
147142
if !diff.is_zero() {
148-
result.copy(((key, val), time1, &diff));
143+
result.copy((data, time1, &diff));
149144
}
150145
}
151146
}
@@ -212,20 +207,20 @@ where
212207
let mut ready = self.empty(stash);
213208

214209
for buffer in merged {
215-
for (key, val, time, diff) in buffer.iter().map(MC::into_parts) {
210+
for (data, time, diff) in buffer.iter().map(MC::into_parts) {
216211
if upper.less_equal(&time) {
217212
frontier.insert_with(&time, |time| (*time).into_owned());
218213
if keep.len() == keep.capacity() && !keep.is_empty() {
219214
kept.push(keep);
220215
keep = self.empty(stash);
221216
}
222-
keep.copy(((key, val), time, diff));
217+
keep.copy((data, time, diff));
223218
} else {
224219
if ready.len() == ready.capacity() && !ready.is_empty() {
225220
readied.push(ready);
226221
ready = self.empty(stash);
227222
}
228-
ready.copy(((key, val), time, diff));
223+
ready.copy((data, time, diff));
229224
}
230225
}
231226
// Recycling buffer.

0 commit comments

Comments
 (0)