@@ -12,25 +12,23 @@ use std::collections::VecDeque;
1212///
1313/// It must implement default for historic reason. The default implementation is not required
1414/// to allocate memory for variable-length components.
15- // TODO: Remove `Default` requirement in the future.
16- // The container is `Default` because `CapacityContainerBuilder` only implements `ContainerBuilder`
17- // for containers that implement `Default`, and we use the associated `::Container` all over Timely.
18- // We can only access the type if all requirements for the `ContainerBuilder` implementation are
19- // satisfied.
2015pub trait WithProgress {
21- /// The number of updates
16+ /// The number of records
2217 ///
2318 /// This number is used in progress tracking to confirm the receipt of some number
24- /// of outstanding updates , and it is highly load bearing. The main restriction is
19+ /// of outstanding records , and it is highly load bearing. The main restriction is
2520 /// imposed on the `LengthPreservingContainerBuilder` trait, whose implementors
26- /// must preserve the number of items .
27- fn update_count ( & self ) -> i64 ;
21+ /// must preserve the number of records .
22+ fn record_count ( & self ) -> i64 ;
2823
2924 /// Determine if this contains any updates, corresponding to `update_count() == 0`.
30- #[ inline] fn is_empty ( & self ) -> bool { self . update_count ( ) == 0 }
25+ #[ inline] fn is_empty ( & self ) -> bool { self . record_count ( ) == 0 }
3126}
3227
33- /// TODO
28+ /// A container that allows iteration.
29+ ///
30+ /// Iterating the container presents items in an implmentation-specific order.
31+ /// The container's contents are not changed.
3432pub trait IterContainer {
3533 /// The type of elements when reading non-destructively from the container.
3634 type ItemRef < ' a > where Self : ' a ;
@@ -40,7 +38,11 @@ pub trait IterContainer {
4038 fn iter ( & self ) -> Self :: Iter < ' _ > ;
4139}
4240
43- /// TODO
41+ /// A container that can drain itself.
42+ ///
43+ /// Draining the container presents items in an implementation-specific order.
44+ /// The container is in an undefined state after calling [`drain`]. Dropping
45+ /// the iterator also leaves the container in an undefined state.
4446pub trait DrainContainer {
4547 /// The type of elements when draining the container.
4648 type Item < ' a > where Self : ' a ;
@@ -60,6 +62,9 @@ pub trait SizableContainer: Sized {
6062 /// The `stash` argument is available, and may have the intended capacity.
6163 /// However, it may be non-empty, and may be of the wrong capacity. The
6264 /// method should guard against these cases.
65+ ///
66+ /// Assume that the `stash` is in an undefined state, and properly clear it
67+ /// before re-using it.
6368 fn ensure_capacity ( & mut self , stash : & mut Option < Self > ) ;
6469}
6570
@@ -85,7 +90,8 @@ pub trait PushInto<T> {
8590///
8691/// The caller should consume the containers returned by [`Self::extract`] and
8792/// [`Self::finish`]. Implementations can recycle buffers, but should ensure that they clear
88- /// any remaining elements.
93+ /// any remaining elements. It is up to the implementation of this trait to ensure that
94+ /// containers are properly cleared before recycling them.
8995///
9096/// For example, a consolidating builder can aggregate differences in-place, but it has
9197/// to ensure that it preserves the intended information.
@@ -108,6 +114,7 @@ pub trait ContainerBuilder: Default + 'static {
108114 #[ must_use]
109115 fn finish ( & mut self ) -> Option < & mut Self :: Container > ;
110116 /// Partitions `container` among `builders`, using the function `index` to direct items.
117+ /// Drains the container. The container is left in an undefined state.
111118 fn partition < I > ( container : & mut Self :: Container , builders : & mut [ Self ] , mut index : I )
112119 where
113120 Self :: Container : DrainContainer ,
@@ -131,7 +138,7 @@ pub trait ContainerBuilder: Default + 'static {
131138
132139/// A wrapper trait indicating that the container building will preserve the number of records.
133140///
134- /// Specifically, the sum of lengths of all extracted and finished containers must equal the
141+ /// Specifically, the sum of record counts of all extracted and finished containers must equal the
135142/// number of times that `push_into` is called on the container builder.
136143/// If you have any questions about this trait you are best off not implementing it.
137144pub trait LengthPreservingContainerBuilder : ContainerBuilder { }
@@ -194,7 +201,7 @@ impl<C: WithProgress + Default + Clone + 'static> ContainerBuilder for CapacityC
194201impl < C : WithProgress + SizableContainer + Default + Clone + ' static > LengthPreservingContainerBuilder for CapacityContainerBuilder < C > { }
195202
196203impl < T > WithProgress for Vec < T > {
197- #[ inline] fn update_count ( & self ) -> i64 { i64:: try_from ( Vec :: len ( self ) ) . unwrap ( ) }
204+ #[ inline] fn record_count ( & self ) -> i64 { i64:: try_from ( Vec :: len ( self ) ) . unwrap ( ) }
198205 #[ inline] fn is_empty ( & self ) -> bool { Vec :: is_empty ( self ) }
199206}
200207
@@ -259,7 +266,7 @@ mod rc {
259266 use crate :: { WithProgress , IterContainer , DrainContainer } ;
260267
261268 impl < T : WithProgress > WithProgress for Rc < T > {
262- #[ inline] fn update_count ( & self ) -> i64 { std:: ops:: Deref :: deref ( self ) . update_count ( ) }
269+ #[ inline] fn record_count ( & self ) -> i64 { std:: ops:: Deref :: deref ( self ) . record_count ( ) }
263270 #[ inline] fn is_empty ( & self ) -> bool { std:: ops:: Deref :: deref ( self ) . is_empty ( ) }
264271 }
265272 impl < T : IterContainer > IterContainer for Rc < T > {
@@ -281,7 +288,7 @@ mod arc {
281288 use crate :: { WithProgress , IterContainer , DrainContainer } ;
282289
283290 impl < T : WithProgress > WithProgress for Arc < T > {
284- #[ inline] fn update_count ( & self ) -> i64 { std:: ops:: Deref :: deref ( self ) . update_count ( ) }
291+ #[ inline] fn record_count ( & self ) -> i64 { std:: ops:: Deref :: deref ( self ) . record_count ( ) }
285292 #[ inline] fn is_empty ( & self ) -> bool { std:: ops:: Deref :: deref ( self ) . is_empty ( ) }
286293 }
287294 impl < T : IterContainer > IterContainer for Arc < T > {
0 commit comments