pub trait DiscreteRangedwhere
    Self: 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§

source

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
source

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

Map a value to the index

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

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

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

Reverse map the index to the value

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

  • value: The index to map
  • returns The value

Provided Methods§

source

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

Return a iterator that iterates over the all possible values

  • returns The value iterator
source

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
source

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

Implementors§