pub trait DiscreteRanged where
Self: Ranged, {
fn size(&self) -> usize;
fn index_of(&self, value: &Self::ValueType) -> Option<usize>;
fn from_index(&self, index: usize) -> Option<Self::ValueType>;
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
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
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
fn from_index(&self, index: usize) -> Option<Self::ValueType>
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
Return a iterator that iterates over the all possible values
- returns The value iterator
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
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