pub struct ChangeBatch<T> { /* private fields */ }
Expand description

A collection of updates of the form (T, i64).

A ChangeBatch accumulates updates of the form (T, i64), where it is capable of consolidating the representation and removing elements whose i64 field accumulates to zero.

The implementation is designed to be as lazy as possible, simply appending to a list of updates until they are required. This means that several seemingly simple operations may be expensive, in that they may provoke a compaction. I’ve tried to prevent exposing methods that allow surprisingly expensive operations; all operations should take an amortized constant or logarithmic time.

Implementations§

source§

impl<T> ChangeBatch<T>

source

pub fn new() -> ChangeBatch<T>

Allocates a new empty ChangeBatch.

§Examples
 use timely::progress::ChangeBatch;

 let mut batch = ChangeBatch::<usize>::new();
 assert!(batch.is_empty());
source

pub fn with_capacity(capacity: usize) -> ChangeBatch<T>

Allocates a new empty ChangeBatch with space for capacity updates.

§Examples
 use timely::progress::ChangeBatch;

 let mut batch = ChangeBatch::<usize>::with_capacity(10);
 assert!(batch.is_empty());
source

pub fn is_dirty(&self) -> bool

Returns true if the change batch is not guaranteed compact.

source

pub fn unstable_internal_updates(&self) -> &Vec<(T, i64)>

Expose the internal vector of updates.

source

pub fn unstable_internal_clean(&self) -> usize

Expose the internal value of clean.

source

pub fn clear(&mut self)

Clears the map.

§Examples
 use timely::progress::ChangeBatch;

 let mut batch = ChangeBatch::<usize>::new_from(17, 1);
 batch.clear();
 assert!(batch.is_empty());
source§

impl<T> ChangeBatch<T>
where T: Ord,

source

pub fn new_from(key: T, val: i64) -> ChangeBatch<T>

Allocates a new ChangeBatch with a single entry.

§Examples
 use timely::progress::ChangeBatch;

 let mut batch = ChangeBatch::<usize>::new_from(17, 1);
 assert!(!batch.is_empty());
source

pub fn update(&mut self, item: T, value: i64)

Adds a new update, for item with value.

This could be optimized to perform compaction when the number of “dirty” elements exceeds half the length of the list, which would keep the total footprint within reasonable bounds even under an arbitrary number of updates. This has a cost, and it isn’t clear whether it is worth paying without some experimentation.

§Examples
 use timely::progress::ChangeBatch;

 let mut batch = ChangeBatch::<usize>::new();
 batch.update(17, 1);
 assert!(!batch.is_empty());
source

pub fn extend<I: Iterator<Item = (T, i64)>>(&mut self, iterator: I)

Performs a sequence of updates described by iterator.

§Examples
 use timely::progress::ChangeBatch;

 let mut batch = ChangeBatch::<usize>::new_from(17, 1);
 batch.extend(vec![(17, -1)].into_iter());
 assert!(batch.is_empty());
source

pub fn into_inner(self) -> Vec<(T, i64)>

Extracts the Vec<(T, i64)> from the map, consuming it.

§Examples
 use timely::progress::ChangeBatch;

 let batch = ChangeBatch::<usize>::new_from(17, 1);
 assert_eq!(batch.into_inner(), vec![(17, 1)]);
source

pub fn iter(&mut self) -> Iter<'_, (T, i64)>

Iterates over the contents of the map.

§Examples
 use timely::progress::ChangeBatch;

 let mut batch = ChangeBatch::<usize>::new_from(17, 1);
 {   // scope allows borrow of `batch` to drop.
     let mut iter = batch.iter();
     assert_eq!(iter.next(), Some(&(17, 1)));
     assert_eq!(iter.next(), None);
 }
 assert!(!batch.is_empty());
source

pub fn drain(&mut self) -> Drain<'_, (T, i64)>

Drains the set of updates.

This operation first compacts the set of updates so that the drained results have at most one occurence of each item.

§Examples
 use timely::progress::ChangeBatch;

 let mut batch = ChangeBatch::<usize>::new_from(17, 1);
 {   // scope allows borrow of `batch` to drop.
     let mut iter = batch.drain();
     assert_eq!(iter.next(), Some((17, 1)));
     assert_eq!(iter.next(), None);
 }
 assert!(batch.is_empty());
source

pub fn is_empty(&mut self) -> bool

True iff all keys have value zero.

This method requires mutable access to self because it may need to compact the representation to determine if the batch of updates is indeed empty. We could also implement a weaker form of is_empty which just checks the length of self.updates, and which could confirm the absence of any updates, but could report false negatives if there are updates which would cancel.

§Examples
 use timely::progress::ChangeBatch;

 let mut batch = ChangeBatch::<usize>::new_from(17, 1);
 batch.update(17, -1);
 assert!(batch.is_empty());
source

pub fn len(&mut self) -> usize

Number of compacted updates.

This method requires mutable access to self because it may need to compact the representation to determine the number of actual updates.

§Examples
 use timely::progress::ChangeBatch;

 let mut batch = ChangeBatch::<usize>::new_from(17, 1);
 batch.update(17, -1);
 batch.update(14, -1);
 assert_eq!(batch.len(), 1);
source

pub fn drain_into(&mut self, other: &mut ChangeBatch<T>)
where T: Clone,

Drains self into other.

This method has similar a effect to calling other.extend(self.drain()), but has the opportunity to optimize this to a ::std::mem::swap(self, other) when other is empty. As many uses of this method are to propagate updates, this optimization can be quite handy.

§Examples
 use timely::progress::ChangeBatch;

 let mut batch1 = ChangeBatch::<usize>::new_from(17, 1);
 let mut batch2 = ChangeBatch::new();
 batch1.drain_into(&mut batch2);
 assert!(batch1.is_empty());
 assert!(!batch2.is_empty());
source

pub fn compact(&mut self)

Compact the internal representation.

This method sort self.updates and consolidates elements with equal item, discarding any whose accumulation is zero. It is optimized to only do this if the number of dirty elements is non-zero.

Trait Implementations§

source§

impl<T> Abomonation for ChangeBatch<T>
where Vec<(T, i64)>: Abomonation, T: Abomonation,

source§

unsafe fn entomb<W: Write>(&self, _write: &mut W) -> Result<()>

Write any additional information about &self beyond its binary representation. Read more
source§

fn extent(&self) -> usize

Reports the number of further bytes required to entomb self.
source§

unsafe fn exhume<'a, 'b>( &'a mut self, bytes: &'b mut [u8] ) -> Option<&'b mut [u8]>

Recover any information for &mut self not evident from its binary representation. Read more
source§

impl<T: Clone> Clone for ChangeBatch<T>

source§

fn clone(&self) -> ChangeBatch<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for ChangeBatch<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> Default for ChangeBatch<T>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'de, T> Deserialize<'de> for ChangeBatch<T>
where T: Deserialize<'de>,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<T: PartialEq> PartialEq for ChangeBatch<T>

source§

fn eq(&self, other: &ChangeBatch<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T> Serialize for ChangeBatch<T>
where T: Serialize,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<T: Eq> Eq for ChangeBatch<T>

source§

impl<T> StructuralPartialEq for ChangeBatch<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for ChangeBatch<T>
where T: RefUnwindSafe,

§

impl<T> Send for ChangeBatch<T>
where T: Send,

§

impl<T> Sync for ChangeBatch<T>
where T: Sync,

§

impl<T> Unpin for ChangeBatch<T>
where T: Unpin,

§

impl<T> UnwindSafe for ChangeBatch<T>
where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ProgressEventTimestamp for T
where T: Data + Debug + Any,

source§

fn as_any(&self) -> &(dyn Any + 'static)

Upcasts this ProgressEventTimestamp to Any. Read more
source§

fn type_name(&self) -> &'static str

Returns the name of the concrete type of this object. Read more
source§

impl<T> PushInto<Vec<T>> for T

source§

fn push_into(self, target: &mut Vec<T>)

Push self into the target container.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> Data for T
where T: Clone + 'static,

source§

impl<T> Data for T
where T: Send + Sync + Any + Serialize + for<'a> Deserialize<'a> + 'static,

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

source§

impl<T> ExchangeData for T
where T: Data + Data,