@@ -6,32 +6,27 @@ use std::collections::VecDeque;
66
77/// A container transferring data through dataflow edges
88///
9- /// A container stores a number of elements and thus is able to describe it length (`len()`) and
10- /// whether it is empty (`is_empty()`).
9+ /// A container stores a number of updates and thus is able to describe it count
10+ /// (`update_count()`) and whether it is empty (`is_empty()`). It is empty if the
11+ /// update count is zero.
1112///
1213/// A container must implement default. The default implementation is not required to allocate
1314/// memory for variable-length components.
14- ///
15- /// We require the container to be cloneable to enable efficient copies when providing references
16- /// of containers to operators. Care must be taken that the type's `clone_from` implementation
17- /// is efficient (which is not necessarily the case when deriving `Clone`.)
1815// The container is `Default` because `CapacityContainerBuilder` only implements `ContainerBuilder`
1916// for containers that implement `Default`, and we use the associated `::Container` all over Timely.
2017// We can only access the type if all requirements for the `ContainerBuilder` implementation are
2118// satisfied.
2219pub trait Container : Default {
23- /// The number of elements in this container
20+ /// The number of updates in this container
2421 ///
2522 /// This number is used in progress tracking to confirm the receipt of some number
26- /// of outstanding records , and it is highly load bearing. The main restriction is
23+ /// of outstanding updates , and it is highly load bearing. The main restriction is
2724 /// imposed on the `LengthPreservingContainerBuilder` trait, whose implementors
2825 /// must preserve the number of items.
29- fn len ( & self ) -> usize ;
26+ fn update_count ( & self ) -> i64 ;
3027
31- /// Determine if the container contains any elements, corresponding to `len() == 0`.
32- fn is_empty ( & self ) -> bool {
33- self . len ( ) == 0
34- }
28+ /// Determine if the container contains any updates, corresponding to `update_count() == 0`.
29+ #[ inline] fn is_empty ( & self ) -> bool { self . update_count ( ) == 0 }
3530}
3631
3732/// TODO
@@ -198,26 +193,22 @@ impl<C: Container + Clone + 'static> ContainerBuilder for CapacityContainerBuild
198193impl < C : Container + Clone + ' static > LengthPreservingContainerBuilder for CapacityContainerBuilder < C > { }
199194
200195impl < T > Container for Vec < T > {
201- fn len ( & self ) -> usize {
202- Vec :: len ( self )
203- }
204- fn is_empty ( & self ) -> bool {
205- Vec :: is_empty ( self )
206- }
196+ #[ inline] fn update_count ( & self ) -> i64 { i64:: try_from ( Vec :: len ( self ) ) . unwrap ( ) }
197+ #[ inline] fn is_empty ( & self ) -> bool { Vec :: is_empty ( self ) }
207198}
208199
209200impl < T > IterContainer for Vec < T > {
210201 type ItemRef < ' a > = & ' a T where T : ' a ;
211202 type Iter < ' a > = std:: slice:: Iter < ' a , T > where Self : ' a ;
212- fn iter ( & self ) -> Self :: Iter < ' _ > {
203+ # [ inline ] fn iter ( & self ) -> Self :: Iter < ' _ > {
213204 self . as_slice ( ) . iter ( )
214205 }
215206}
216207
217208impl < T > DrainContainer for Vec < T > {
218209 type Item < ' a > = T where T : ' a ;
219210 type DrainIter < ' a > = std:: vec:: Drain < ' a , T > where Self : ' a ;
220- fn drain ( & mut self ) -> Self :: DrainIter < ' _ > {
211+ # [ inline ] fn drain ( & mut self ) -> Self :: DrainIter < ' _ > {
221212 self . drain ( ..)
222213 }
223214}
@@ -267,22 +258,18 @@ mod rc {
267258 use crate :: { Container , IterContainer , DrainContainer } ;
268259
269260 impl < T : Container > Container for Rc < T > {
270- fn len ( & self ) -> usize {
271- std:: ops:: Deref :: deref ( self ) . len ( )
272- }
273- fn is_empty ( & self ) -> bool {
274- std:: ops:: Deref :: deref ( self ) . is_empty ( )
275- }
261+ #[ inline] fn update_count ( & self ) -> i64 { std:: ops:: Deref :: deref ( self ) . update_count ( ) }
262+ #[ inline] fn is_empty ( & self ) -> bool { std:: ops:: Deref :: deref ( self ) . is_empty ( ) }
276263 }
277264 impl < T : IterContainer > IterContainer for Rc < T > {
278265 type ItemRef < ' a > = T :: ItemRef < ' a > where Self : ' a ;
279266 type Iter < ' a > = T :: Iter < ' a > where Self : ' a ;
280- fn iter ( & self ) -> Self :: Iter < ' _ > { self . deref ( ) . iter ( ) }
267+ # [ inline ] fn iter ( & self ) -> Self :: Iter < ' _ > { self . deref ( ) . iter ( ) }
281268 }
282269 impl < T : IterContainer > DrainContainer for Rc < T > {
283270 type Item < ' a > = T :: ItemRef < ' a > where Self : ' a ;
284271 type DrainIter < ' a > = T :: Iter < ' a > where Self : ' a ;
285- fn drain ( & mut self ) -> Self :: DrainIter < ' _ > { self . iter ( ) }
272+ # [ inline ] fn drain ( & mut self ) -> Self :: DrainIter < ' _ > { self . iter ( ) }
286273 }
287274}
288275
@@ -293,18 +280,18 @@ mod arc {
293280 use crate :: { Container , IterContainer , DrainContainer } ;
294281
295282 impl < T : Container > Container for Arc < T > {
296- fn len ( & self ) -> usize { std:: ops:: Deref :: deref ( self ) . len ( ) }
297- fn is_empty ( & self ) -> bool { std:: ops:: Deref :: deref ( self ) . is_empty ( ) }
283+ # [ inline ] fn update_count ( & self ) -> i64 { std:: ops:: Deref :: deref ( self ) . update_count ( ) }
284+ # [ inline ] fn is_empty ( & self ) -> bool { std:: ops:: Deref :: deref ( self ) . is_empty ( ) }
298285 }
299286 impl < T : IterContainer > IterContainer for Arc < T > {
300287 type ItemRef < ' a > = T :: ItemRef < ' a > where Self : ' a ;
301288 type Iter < ' a > = T :: Iter < ' a > where Self : ' a ;
302- fn iter ( & self ) -> Self :: Iter < ' _ > { self . deref ( ) . iter ( ) }
289+ # [ inline ] fn iter ( & self ) -> Self :: Iter < ' _ > { self . deref ( ) . iter ( ) }
303290 }
304291 impl < T : IterContainer > DrainContainer for Arc < T > {
305292 type Item < ' a > = T :: ItemRef < ' a > where Self : ' a ;
306293 type DrainIter < ' a > = T :: Iter < ' a > where Self : ' a ;
307- fn drain ( & mut self ) -> Self :: DrainIter < ' _ > { self . iter ( ) }
294+ # [ inline ] fn drain ( & mut self ) -> Self :: DrainIter < ' _ > { self . iter ( ) }
308295 }
309296}
310297
0 commit comments