Struct HashableIndex

Source
pub struct HashableIndex<TIndex: Serialize + Hash + Clone + Eq + Ord> {
    pub values: Vec<TIndex>,
}
Expand description

a HashableIndex serves as the index for a timeseries, it requires that the index element be Serializatable (via serde), Hashable, Cloneable, Equatable, and Orderable.

Fields§

§values: Vec<TIndex>

Implementations§

Source§

impl HashableIndex<NaiveDateTime>

Source§

impl<TIndex: Serialize + Hash + Clone + Eq + Ord> HashableIndex<TIndex>

Source

pub fn new(values: Vec<TIndex>) -> HashableIndex<TIndex>

Create new index from a vec of values of type TIndex

§Example
use tsxlib::index::HashableIndex;

let values = vec![1, 2, 3, 4];
let index = HashableIndex::new(values);
assert_eq!(index.len(), 4);
Source

pub fn is_monotonic(&self) -> bool

test the monotonicity test for an index

§Example
use tsxlib::index::HashableIndex;

let vs = HashableIndex::new(vec![1, 2, 3, 4]);
let xs = HashableIndex::new(vec![1, 2, 3, 3]);
let ys = HashableIndex::new(vec![1, 2, 3, 2]);
assert_eq!(vs.is_monotonic(), true);
assert_eq!(xs.is_monotonic(), false);
assert_eq!(ys.is_monotonic(), false);
Source

pub fn len(&self) -> usize

get length of the index

Source

pub fn is_empty(&self) -> bool

is the index empty

Source

pub fn last(&self) -> Option<&TIndex>

ref to the last value of an index

Source

pub fn is_unique(&self) -> bool

very slow, tests if index is unique by generating a hashset of the index keys and then comparing lengths

Source

pub fn iter(&self) -> Iter<'_, TIndex>

generate and iterator for the index

Trait Implementations§

Source§

impl<TIndex: Clone + Serialize + Hash + Clone + Eq + Ord> Clone for HashableIndex<TIndex>

Source§

fn clone(&self) -> HashableIndex<TIndex>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<TIndex: Debug + Serialize + Hash + Clone + Eq + Ord> Debug for HashableIndex<TIndex>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<TIndex: Serialize + Hash + Clone + Eq + Ord> Index<usize> for HashableIndex<TIndex>

Source§

type Output = TIndex

The returned type after indexing.
Source§

fn index(&self, pos: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<TIndex: Serialize + Hash + Clone + Eq + Ord> PartialEq for HashableIndex<TIndex>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl SampleableIndex<NaiveDateTime, Duration> for HashableIndex<NaiveDateTime>

Implementation of SampleableIndex for HashableIndex

Source§

fn sample_rates(&self) -> Vec<(usize, Duration)>

Infer index sample rate, returns a vector that represtest (number of times a sample rate is observed, the sample rate)

§Example
use tsxlib::index::HashableIndex;
use tsxlib::index::SampleableIndex;
use tsxlib::timeutils;
use chrono::{NaiveDateTime,Duration};
 
let index = HashableIndex::new(vec![ timeutils::naive_datetime_from_millis(0), timeutils::naive_datetime_from_millis(5),timeutils::naive_datetime_from_millis(10), timeutils::naive_datetime_from_millis(15), timeutils::naive_datetime_from_millis(20), timeutils::naive_datetime_from_millis(25), timeutils::naive_datetime_from_millis(75)]);
let exp =  vec![(5,Duration::milliseconds(5)),(1,Duration::milliseconds(50))];
assert_eq!(index.sample_rates(), exp);
Source§

fn is_mono_intervaled(&self) -> bool

returns true if the index is spaced at equal itervals

§Example
use tsxlib::index::HashableIndex;
use tsxlib::index::SampleableIndex;
use tsxlib::timeutils;
use chrono::{NaiveDateTime,Duration};
 
let index = HashableIndex::new(vec![ timeutils::naive_datetime_from_millis(0), timeutils::naive_datetime_from_millis(5),timeutils::naive_datetime_from_millis(10), timeutils::naive_datetime_from_millis(15), timeutils::naive_datetime_from_millis(20), timeutils::naive_datetime_from_millis(25), timeutils::naive_datetime_from_millis(75)]);
let index_mono = HashableIndex::new(vec![ timeutils::naive_datetime_from_millis(0), timeutils::naive_datetime_from_millis(5),timeutils::naive_datetime_from_millis(10), timeutils::naive_datetime_from_millis(15), timeutils::naive_datetime_from_millis(20), timeutils::naive_datetime_from_millis(25)]);
assert_eq!(index.is_mono_intervaled(), false);
assert_eq!(index_mono.is_mono_intervaled(), true);

Auto Trait Implementations§

§

impl<TIndex> Freeze for HashableIndex<TIndex>

§

impl<TIndex> RefUnwindSafe for HashableIndex<TIndex>
where TIndex: RefUnwindSafe,

§

impl<TIndex> Send for HashableIndex<TIndex>
where TIndex: Send,

§

impl<TIndex> Sync for HashableIndex<TIndex>
where TIndex: Sync,

§

impl<TIndex> Unpin for HashableIndex<TIndex>
where TIndex: Unpin,

§

impl<TIndex> UnwindSafe for HashableIndex<TIndex>
where TIndex: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.