11//! Wordcount based on `columnar`.
22
3- use {
4- timely:: container:: { Container , CapacityContainerBuilder } ,
5- timely:: dataflow:: channels:: pact:: ExchangeCore ,
6- timely:: dataflow:: InputHandleCore ,
7- timely:: dataflow:: ProbeHandle ,
8- } ;
3+ use timely:: container:: { CapacityContainerBuilder , PushInto } ;
4+ use timely:: dataflow:: channels:: pact:: ExchangeCore ;
5+ use timely:: dataflow:: InputHandleCore ;
6+ use timely:: dataflow:: ProbeHandle ;
97
108use differential_dataflow:: trace:: implementations:: ord_neu:: ColKeySpine ;
119
@@ -65,7 +63,7 @@ fn main() {
6563 while i < size {
6664 let val = ( counter + i) % keys;
6765 write ! ( buffer, "{:?}" , val) . unwrap ( ) ;
68- container. push ( ( ( & buffer, ( ) ) , time, 1 ) ) ;
66+ container. push_into ( ( ( & buffer, ( ) ) , time, 1 ) ) ;
6967 buffer. clear ( ) ;
7068 i += worker. peers ( ) ;
7169 }
@@ -88,7 +86,7 @@ fn main() {
8886 while i < size {
8987 let val = ( queries + i) % keys;
9088 write ! ( buffer, "{:?}" , val) . unwrap ( ) ;
91- container. push ( ( ( & buffer, ( ) ) , time, 1 ) ) ;
89+ container. push_into ( ( ( & buffer, ( ) ) , time, 1 ) ) ;
9290 buffer. clear ( ) ;
9391 i += worker. peers ( ) ;
9492 }
@@ -169,26 +167,29 @@ mod container {
169167 pub fn get ( & self , index : usize ) -> columnar:: Ref < ' _ , C > {
170168 self . borrow ( ) . get ( index)
171169 }
172- }
173-
174- use timely:: Container ;
175- impl < C : Columnar > Container for Column < C > {
176- fn len ( & self ) -> usize {
177- match self {
178- Column :: Typed ( t) => t. len ( ) ,
179- Column :: Bytes ( b) => <BorrowedOf < C > as FromBytes >:: from_bytes ( & mut Indexed :: decode ( bytemuck:: cast_slice ( b) ) ) . len ( ) ,
180- Column :: Align ( a) => <BorrowedOf < C > as FromBytes >:: from_bytes ( & mut Indexed :: decode ( a) ) . len ( ) ,
181- }
182- }
183170 // This sets the `Bytes` variant to be an empty `Typed` variant, appropriate for pushing into.
184- fn clear ( & mut self ) {
171+ pub ( crate ) fn clear ( & mut self ) {
185172 match self {
186173 Column :: Typed ( t) => t. clear ( ) ,
187174 Column :: Bytes ( _) => * self = Column :: Typed ( Default :: default ( ) ) ,
188175 Column :: Align ( _) => * self = Column :: Typed ( Default :: default ( ) ) ,
189176 }
190177 }
178+ #[ inline]
179+ pub fn len ( & self ) -> usize {
180+ match self {
181+ Column :: Typed ( t) => t. len ( ) ,
182+ Column :: Bytes ( b) => <BorrowedOf < C > as FromBytes >:: from_bytes ( & mut Indexed :: decode ( bytemuck:: cast_slice ( b) ) ) . len ( ) ,
183+ Column :: Align ( a) => <BorrowedOf < C > as FromBytes >:: from_bytes ( & mut Indexed :: decode ( a) ) . len ( ) ,
184+ }
185+ }
186+ }
187+
188+ impl < C : Columnar > timely:: Accountable for Column < C > {
189+ #[ inline] fn record_count ( & self ) -> i64 { self . len ( ) as i64 }
190+ }
191191
192+ impl < C : Columnar > timely:: container:: IterContainer for Column < C > {
192193 type ItemRef < ' a > = columnar:: Ref < ' a , C > ;
193194 type Iter < ' a > = IterOwn < BorrowedOf < ' a , C > > ;
194195 fn iter < ' a > ( & ' a self ) -> Self :: Iter < ' a > {
@@ -198,7 +199,9 @@ mod container {
198199 Column :: Align ( a) => <BorrowedOf < C > as FromBytes >:: from_bytes ( & mut Indexed :: decode ( a) ) . into_index_iter ( ) ,
199200 }
200201 }
202+ }
201203
204+ impl < C : Columnar > timely:: container:: DrainContainer for Column < C > {
202205 type Item < ' a > = columnar:: Ref < ' a , C > ;
203206 type DrainIter < ' a > = IterOwn < BorrowedOf < ' a , C > > ;
204207 fn drain < ' a > ( & ' a mut self ) -> Self :: DrainIter < ' a > {
@@ -366,7 +369,7 @@ pub mod batcher {
366369 use std:: collections:: VecDeque ;
367370 use columnar:: Columnar ;
368371 use timely:: Container ;
369- use timely:: container:: { ContainerBuilder , PushInto } ;
372+ use timely:: container:: { ContainerBuilder , DrainContainer , PushInto , SizableContainer } ;
370373 use differential_dataflow:: difference:: Semigroup ;
371374 use crate :: Column ;
372375
@@ -389,7 +392,7 @@ pub mod batcher {
389392 ready : VecDeque < C > ,
390393 }
391394
392- impl < C : Container + Clone + ' static > ContainerBuilder for Chunker < C > {
395+ impl < C : Container > ContainerBuilder for Chunker < C > {
393396 type Container = C ;
394397
395398 fn extract ( & mut self ) -> Option < & mut Self :: Container > {
@@ -414,9 +417,11 @@ pub mod batcher {
414417 for < ' b > columnar:: Ref < ' b , T > : Ord ,
415418 R : for < ' b > Columnar + for < ' b > Semigroup < columnar:: Ref < ' b , R > > ,
416419 for < ' b > columnar:: Ref < ' b , R > : Ord ,
417- C2 : Container + for < ' b , ' c > PushInto < ( columnar:: Ref < ' b , D > , columnar:: Ref < ' b , T > , & ' c R ) > ,
420+ C2 : Container + SizableContainer + for < ' b , ' c > PushInto < ( columnar:: Ref < ' b , D > , columnar:: Ref < ' b , T > , & ' c R ) > ,
418421 {
419422 fn push_into ( & mut self , container : & ' a mut Column < ( D , T , R ) > ) {
423+ let mut target: C2 = Default :: default ( ) ;
424+ target. ensure_capacity ( & mut Some ( std:: mem:: take ( & mut self . empty ) ) ) ;
420425
421426 // Scoped to let borrow through `permutation` drop.
422427 {
@@ -426,7 +431,6 @@ pub mod batcher {
426431 permutation. extend ( container. drain ( ) ) ;
427432 permutation. sort ( ) ;
428433
429- self . empty . clear ( ) ;
430434 // Iterate over the data, accumulating diffs for like keys.
431435 let mut iter = permutation. drain ( ..) ;
432436 if let Some ( ( data, time, diff) ) = iter. next ( ) {
@@ -442,7 +446,7 @@ pub mod batcher {
442446 else {
443447 if !prev_diff. is_zero ( ) {
444448 let tuple = ( prev_data, prev_time, & prev_diff) ;
445- self . empty . push_into ( tuple) ;
449+ target . push_into ( tuple) ;
446450 }
447451 prev_data = data;
448452 prev_time = time;
@@ -452,13 +456,13 @@ pub mod batcher {
452456
453457 if !prev_diff. is_zero ( ) {
454458 let tuple = ( prev_data, prev_time, & prev_diff) ;
455- self . empty . push_into ( tuple) ;
459+ target . push_into ( tuple) ;
456460 }
457461 }
458462 }
459463
460- if !self . empty . is_empty ( ) {
461- self . ready . push_back ( std :: mem :: take ( & mut self . empty ) ) ;
464+ if !target . is_empty ( ) {
465+ self . ready . push_back ( target ) ;
462466 }
463467 }
464468 }
@@ -468,7 +472,7 @@ pub mod batcher {
468472
469473 use timely:: progress:: { Antichain , frontier:: AntichainRef } ;
470474 use columnar:: Columnar ;
471-
475+ use timely :: container :: PushInto ;
472476 use crate :: container:: Column ;
473477 use differential_dataflow:: difference:: Semigroup ;
474478
@@ -502,7 +506,6 @@ pub mod batcher {
502506 }
503507 }
504508 fn is_empty ( & self ) -> bool {
505- use timely:: Container ;
506509 self . head == self . list . len ( )
507510 }
508511 fn cmp_heads ( & self , other : & Self ) -> std:: cmp:: Ordering {
@@ -551,8 +554,7 @@ pub mod batcher {
551554 let stash2: R = R :: into_owned ( diff2) ;
552555 stash. plus_equals ( & stash2) ;
553556 if !stash. is_zero ( ) {
554- use timely:: Container ;
555- self . push ( ( data, time, & * stash) ) ;
557+ self . push_into ( ( data, time, & * stash) ) ;
556558 }
557559 }
558560 fn account ( & self ) -> ( usize , usize , usize , usize ) {
@@ -568,6 +570,7 @@ pub mod batcher {
568570 // self.heap_size(cb);
569571 // (self.len(), size, capacity, allocations)
570572 }
573+ #[ inline] fn clear ( & mut self ) { self . clear ( ) }
571574 }
572575 }
573576
@@ -578,7 +581,7 @@ use dd_builder::ColKeyBuilder;
578581pub mod dd_builder {
579582
580583 use columnar:: Columnar ;
581-
584+ use timely :: container :: DrainContainer ;
582585 use differential_dataflow:: trace:: Builder ;
583586 use differential_dataflow:: trace:: Description ;
584587 use differential_dataflow:: trace:: implementations:: Layout ;
@@ -630,8 +633,6 @@ pub mod dd_builder {
630633
631634 #[ inline]
632635 fn push ( & mut self , chunk : & mut Self :: Input ) {
633- use timely:: Container ;
634-
635636 // NB: Maintaining owned key and val across iterations to track the "last", which we clone into,
636637 // is somewhat appealing from an ease point of view. Might still allocate, do work we don't need,
637638 // but avoids e.g. calls into `last()` and breaks horrid trait requirements.
@@ -737,8 +738,6 @@ pub mod dd_builder {
737738
738739 #[ inline]
739740 fn push ( & mut self , chunk : & mut Self :: Input ) {
740- use timely:: Container ;
741-
742741 // NB: Maintaining owned key and val across iterations to track the "last", which we clone into,
743742 // is somewhat appealing from an ease point of view. Might still allocate, do work we don't need,
744743 // but avoids e.g. calls into `last()` and breaks horrid trait requirements.
0 commit comments