pub enum SeriesMapping {
Aligned {
first: i64,
},
Mapped {
first: i64,
offsets: Vec<u32>,
},
}Expand description
How the points of one series map to logical indices of the TimeIndex.
§Examples
use ferrochart_core::data::{SeriesMapping, TimeIndex};
let index = TimeIndex::from_times(vec![10, 20, 30, 40])?;
// A contiguous run of the index (e.g. an indicator computed from the main series).
let aligned = index.map_series(&[20, 30, 40])?;
assert_eq!(aligned, Some(SeriesMapping::Aligned { first: 1 }));
// A sparse subset needs a lookup table.
let mapped = index.map_series(&[10, 40])?.unwrap();
assert!(!mapped.is_aligned());
assert_eq!(mapped.logical_index(1), Some(3));
// Not a subset: the caller has to merge.
assert_eq!(index.map_series(&[15])?, None);Variants§
Aligned
Fast path: point i of the series is at logical index first + i. No
per-point memory.
Mapped
General path: point i is at logical index first + offsets[i].
offsets is strictly increasing and starts at 0. 4 bytes per point.
Implementations§
Source§impl SeriesMapping
impl SeriesMapping
Sourcepub fn is_aligned(&self) -> bool
pub fn is_aligned(&self) -> bool
Sourcepub fn logical_index(&self, i: usize) -> Option<i64>
pub fn logical_index(&self, i: usize) -> Option<i64>
Logical index of point i of the series. For Mapped, None if i is
out of range; for Aligned, None only if the index overflows i64.
§Examples
use ferrochart_core::data::SeriesMapping;
let m = SeriesMapping::Mapped { first: -5, offsets: vec![0, 2, 7] };
assert_eq!(m.logical_index(1), Some(-3));
assert_eq!(m.logical_index(3), None);Trait Implementations§
Source§impl Clone for SeriesMapping
impl Clone for SeriesMapping
Source§impl Debug for SeriesMapping
impl Debug for SeriesMapping
impl Eq for SeriesMapping
Source§impl PartialEq for SeriesMapping
impl PartialEq for SeriesMapping
impl StructuralPartialEq for SeriesMapping
Auto Trait Implementations§
impl Forget for SeriesMapping
impl Freeze for SeriesMapping
impl Move for SeriesMapping
impl RefUnwindSafe for SeriesMapping
impl Send for SeriesMapping
impl Sync for SeriesMapping
impl Unpin for SeriesMapping
impl UnsafeUnpin for SeriesMapping
impl UnwindSafe for SeriesMapping
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more