[][src]Struct tsxlib::index::HashableIndex

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

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

impl HashableIndex<NaiveDateTime>[src]

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

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

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);

pub fn is_monotonic(&self) -> bool[src]

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);

pub fn len(&self) -> usize[src]

get length of the index

pub fn is_empty(&self) -> bool[src]

is the index empty

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

ref to the last value of an index

pub fn is_unique(&self) -> bool[src]

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

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

generate and iterator for the index

Trait Implementations

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

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

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

type Output = TIndex

The returned type after indexing.

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

impl SampleableIndex<NaiveDateTime, Duration> for HashableIndex<NaiveDateTime>[src]

Implementation of SampleableIndex for HashableIndex

pub fn sample_rates(&self) -> Vec<(usize, Duration)>[src]

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);

pub fn is_mono_intervaled(&self) -> bool[src]

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> RefUnwindSafe for HashableIndex<TIndex> where
    TIndex: RefUnwindSafe
[src]

impl<TIndex> Send for HashableIndex<TIndex> where
    TIndex: Send
[src]

impl<TIndex> Sync for HashableIndex<TIndex> where
    TIndex: Sync
[src]

impl<TIndex> Unpin for HashableIndex<TIndex> where
    TIndex: Unpin
[src]

impl<TIndex> UnwindSafe for HashableIndex<TIndex> where
    TIndex: UnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.