[][src]Struct math::iter::binned_interval_iter::BinnedIntervalIter

pub struct BinnedIntervalIter<I, V> where
    I: Iterator,
    V: Copy + Num + FromPrimitive + PartialOrd
{ /* fields omitted */ }

With imaginary bins of size bin_size and aligned at 0, returns a value for each bin that intersects one or more intervals from the original iterator iter, where the value at each intersection is obtained by applying the operation specified by the aggregate_op for all the overlapping intervals and their associated values, where the value of each overlapping interval is multiplied by the length of the interval if the aggregate_op is Sum.

Panics

The iterator will panic if the intervals returned by the original iter are not disjoint or increasing.

Example

use math::{
    interval::I64Interval,
    iter::binned_interval_iter::{AggregateOp, IntoBinnedIntervalIter},
    partition::integer_interval_map::IntegerIntervalMap,
};

let bin_size = 5;
let mut interval_map = IntegerIntervalMap::new();
interval_map.aggregate(I64Interval::new(-1, 1), 2);
interval_map.aggregate(I64Interval::new(14, 17), -1);

// interval coordinates                       | value
// -1 | 0 1  |   ...   |        |              | +2
//    |      |   ...   |     14 | 15 16 17     | -1
//---------------------------------------------
//  2 || 4   ||  ...   || -1   || -3          | bin sum
//  2 || 2   ||  ...   || -1   || -1          | bin max
//  2 || 2   ||  ...   || -1   || -1          | bin min
assert_eq!(
    interval_map
        .iter()
        .into_binned_interval_iter(
            bin_size,
            AggregateOp::Sum,
            Box::new(|(&interval, &val)| (interval, val))
        )
        .collect::<Vec<(I64Interval, i32)>>(),
    vec![
        (I64Interval::new(-5, -1), 2),
        (I64Interval::new(0, 4), 4),
        (I64Interval::new(10, 14), -1),
        (I64Interval::new(15, 19), -3),
    ]
);
assert_eq!(
    interval_map
        .iter()
        .into_binned_interval_iter(
            bin_size,
            AggregateOp::Max,
            Box::new(|(&interval, &val)| (interval, val))
        )
        .collect::<Vec<(I64Interval, i32)>>(),
    vec![
        (I64Interval::new(-5, -1), 2),
        (I64Interval::new(0, 4), 2),
        (I64Interval::new(10, 14), -1),
        (I64Interval::new(15, 19), -1),
    ]
);
assert_eq!(
    interval_map
        .iter()
        .into_binned_interval_iter(
            bin_size,
            AggregateOp::Min,
            Box::new(|(&interval, &val)| (interval, val))
        )
        .collect::<Vec<(I64Interval, i32)>>(),
    vec![
        (I64Interval::new(-5, -1), 2),
        (I64Interval::new(0, 4), 2),
        (I64Interval::new(10, 14), -1),
        (I64Interval::new(15, 19), -1),
    ]
);

Implementations

impl<I, V> BinnedIntervalIter<I, V> where
    I: Iterator,
    V: Copy + Num + FromPrimitive + PartialOrd
[src]

pub fn new(
    iter: I,
    bin_size: i64,
    aggregate_op: AggregateOp,
    iter_item_interval_value_extractor: Box<dyn Fn(<I as Iterator>::Item) -> (I64Interval, V)>
) -> Self
[src]

Trait Implementations

impl<I, V> CommonRefinementZip<i64, (ContiguousIntegerSet<i64>, V), ContiguousIntegerSet<i64>, V> for BinnedIntervalIter<I, V> where
    I: Iterator,
    V: Copy + Num + FromPrimitive + PartialOrd
[src]

impl<I, V> Iterator for BinnedIntervalIter<I, V> where
    I: Iterator,
    V: Copy + Num + FromPrimitive + PartialOrd
[src]

type Item = (I64Interval, V)

The type of the elements being iterated over.

fn next(&mut self) -> Option<Self::Item>[src]

After every iteration, self.current_bin can be

  • None: indicating that the current interval has not been processed at all
  • Some: indicating the last used bin

and self.current_interval_val can be

  • None: indicating that all the intervals have been processed
  • Some: indicating that the current interval still has unprocessed elements

panics: if the intervals returned by the original iter are not disjoint or increasing.

Auto Trait Implementations

impl<I, V> !RefUnwindSafe for BinnedIntervalIter<I, V>

impl<I, V> !Send for BinnedIntervalIter<I, V>

impl<I, V> !Sync for BinnedIntervalIter<I, V>

impl<I, V> Unpin for BinnedIntervalIter<I, V> where
    I: Unpin,
    V: Unpin

impl<I, V> !UnwindSafe for BinnedIntervalIter<I, V>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I, V> IntoBinnedIntervalIter<V> for I where
    I: Iterator,
    V: Copy + Num + FromPrimitive + PartialOrd<V>, 
[src]

impl<I> IntoConcatIter for I where
    I: Iterator
[src]

impl<I> IntoFlatZipIter<I> for I where
    I: Iterator
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<I> IteratorRandom for I where
    I: Iterator
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,