Trait DiscreteRanged

pub trait DiscreteRanged: Ranged {
    // Required methods
    fn size(&self) -> usize;
    fn index_of(&self, value: &Self::ValueType) -> Option<usize>;
    fn from_index(&self, index: usize) -> Option<Self::ValueType>;

    // Provided methods
    fn values(&self) -> DiscreteValueIter<'_, Self>
       where Self: Sized { ... }
    fn previous(&self, value: &Self::ValueType) -> Option<Self::ValueType> { ... }
    fn next(&self, value: &Self::ValueType) -> Option<Self::ValueType> { ... }
}
Expand description

The trait indicates the coordinate is discrete This means we can bidirectionally map the range value to 0 to N in which N is the number of distinct values of the range.

This is useful since for a histgoram, this is an abstraction of bucket.

Required Methods§

fn size(&self) -> usize

Get the number of element in the range Note: we assume that all the ranged discrete coordinate has finite value

  • returns The number of values in the range

fn index_of(&self, value: &Self::ValueType) -> Option<usize>

Map a value to the index

Note: This function doesn’t guarantee return None when the value is out of range. The only way to confirm the value is in the range is to examining the return value isn’t larger than self.size.

  • value: The value to map
  • returns The index of the value

fn from_index(&self, index: usize) -> Option<Self::ValueType>

Reverse map the index to the value

Note: This function doesn’t guarantee returning None when the index is out of range.

  • value: The index to map
  • returns The value

Provided Methods§

fn values(&self) -> DiscreteValueIter<'_, Self>
where Self: Sized,

Return a iterator that iterates over the all possible values

  • returns The value iterator

fn previous(&self, value: &Self::ValueType) -> Option<Self::ValueType>

Returns the previous value in this range

Normally, it’s based on the from_index and index_of function. But for some of the coord spec, it’s possible that we value faster implementation. If this is the case, we can impelemnet the type specific impl for the previous and next.

  • value: The current value
  • returns: The value piror to current value

fn next(&self, value: &Self::ValueType) -> Option<Self::ValueType>

Returns the next value in this range

Normally, it’s based on the from_index and index_of function. But for some of the coord spec, it’s possible that we value faster implementation. If this is the case, we can impelemnet the type specific impl for the previous and next.

  • value: The current value
  • returns: The value next to current value

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

§

impl DiscreteRanged for RangedCoordi32

§

impl DiscreteRanged for RangedCoordi64

§

impl DiscreteRanged for RangedCoordi128

§

impl DiscreteRanged for RangedCoordisize

§

impl DiscreteRanged for RangedCoordu32

§

impl DiscreteRanged for RangedCoordu64

§

impl DiscreteRanged for RangedCoordu128

§

impl DiscreteRanged for RangedCoordusize

§

impl<'a, T> DiscreteRanged for RangedSlice<'a, T>
where T: PartialEq,

§

impl<D> DiscreteRanged for RangedDate<D>
where D: TimeValue + Sub<Output = TimeDelta> + Add<TimeDelta, Output = D> + Datelike + Clone,

§

impl<D> DiscreteRanged for SegmentedCoord<D>
where D: DiscreteRanged,

§

impl<P, S> DiscreteRanged for NestedRange<P, S>

§

impl<R> DiscreteRanged for WithKeyPointMethod<R>
where R: DiscreteRanged,

§

impl<R> DiscreteRanged for WithKeyPoints<R>
where R: DiscreteRanged, <R as Ranged>::ValueType: Clone,

§

impl<T> DiscreteRanged for GroupBy<T>
where T: DiscreteRanged,

§

impl<T> DiscreteRanged for Monthly<T>
where T: TimeValue + Clone, Range<T>: AsRangedCoord<Value = T>,

§

impl<T> DiscreteRanged for Yearly<T>
where T: TimeValue + Clone, Range<T>: AsRangedCoord<Value = T>,

§

impl<T, S, R> DiscreteRanged for Linspace<T, S, R>
where T: Ranged, S: Clone, R: LinspaceRoundingMethod<<T as Ranged>::ValueType>, <T as Ranged>::ValueType: Add<S, Output = <T as Ranged>::ValueType> + PartialOrd + Clone,