Collection

Struct Collection 

Source
pub struct Collection<T: Serializable> {
    pub vec: Vec<T>,
}
Expand description

A wrapper around the std::vec::vec

§Note

  • Collection only implements some basic functionality of real Vecs. The goal is not to supersede, but to add to. So you should use Vec in most cases, and wrap it in a Collection if you need one of those functions.

Fields§

§vec: Vec<T>

Implementations§

Source§

impl<T: Serializable> Collection<T>

Source

pub fn empty() -> Collection<T>

Returns new Collection from a Vec<T: Serializable>

§Example
use calcify::FourVec;
use calcify::Collection;

let col4V: Collection<FourVec> = Collection::empty();
Source

pub fn at(&mut self, i: usize) -> &mut T

Returns a mutable reference to the T: Serializable at index i

§Arguments
  • i - usize
§Example
use calcify::FourVec;
use calcify::Collection;

let mut col4V = Collection::from(
    vec![FourVec::new(10.0,1.0,1.0,1.0)]
);
assert_eq!(*col4V.at(0),FourVec::new(10.0,1.0,1.0,1.0));
*col4V.at(0) += FourVec::new(10.0,1.0,1.0,1.0);
assert_eq!(*col4V.at(0),FourVec::new(20.0,2.0,2.0,2.0));
Source

pub fn push(&mut self, nn: T)

Push new T: Serializable into Collection

§Arguments
  • nn - T: Serializable
§Example
use calcify::FourVec;
use calcify::Collection;

let mut col4V = Collection::empty();
col4V.push(FourVec::new(10.0,1.0,1.0,1.0));
assert_eq!(*col4V.at(0),FourVec::new(10.0,1.0,1.0,1.0));
Source

pub fn map<F, Z: Serializable>(&self, close: F) -> Collection<Z>
where F: FnMut(&T) -> Z,

Maps a function and returns a new Collection

Implements Vec::iter::map and Vec::iter::collect.

§Arguments
  • close - F: FnMut(&T: Serializable) -> Z: Serializable
§Example
use calcify::FourVec;
use calcify::Collection;

let mut col4V: Collection<FourVec> = Collection::empty();
for _i in 0..9999 {
    col4V.push(FourVec::new(1.0,0.0,0.0,0.0));
}
let mut mass_col4V: Collection<f64> = Collection::empty();
for _i in 0..9999 {
    mass_col4V.push(1.0);
}
assert_eq!(col4V.map(FourVec::s), mass_col4V);
Source

pub fn cut<F>(&self, close: F) -> Collection<T>
where F: FnMut(&&T) -> bool, T: Clone,

Cuts/Filters a function and returns a new Collection

Implements Vec::iter::filter and Vec::iter::collect.

§Note
  • This may behave differently than expected. Cut keeps the elements that pass the test, not fail it.
§Arguments
  • close - F: FnMut(&&T: Serializable) -> bool
§Example
use calcify::FourVec;
use calcify::Collection;

let mut col4V: Collection<FourVec> = Collection::empty();
for _i in 0..9999 {
    col4V.push(FourVec::new(1.0,0.0,0.0,0.0));
}
col4V.cut(|&&x| x.s() < 10.0);
Source

pub fn len(&self) -> usize

Source§

impl Collection<Point>

Source

pub fn plot(ind: &[f64], dep: &[f64]) -> Collection<Point>

Return Collection plot

§Arguments
  • ind - Independent variable: &f64
  • dep - Dependent variable: &f64
§Example
use calcify::Collection;
use calcify::Point;

let test_plot: Collection<Point> = Collection::plot(&vec![0.0,1.0,2.0],&vec![3.0,4.0,5.0]);
Source

pub fn hist(&self, num_bins_x: u64, num_bins_y: u64) -> Collection<PointBin>

Return Collection 2D histogram

§Arguments
  • num_bins_x - Number of bins along the x axis: u64 (>= 2)
  • num_bins_y - Number of bins along the y axis: u64 (>= 2)
§Panics
  • If either num_bins is less than 2
Source§

impl Collection<f64>

Source

pub fn hist(&self, num_bins: u64) -> Collection<Bin>

Return Collection histogram

§Arguments
  • num_bins - Number of bins: u64 (>= 2)
§Panics
  • If num_bins is less than 2
§Example
use calcify::Collection;
use calcify::Bin;
use calcify::ThreeVec;

let mut col_3v = Collection::empty();
    for _i in 0..99999 {
        col_3v.push(ThreeVec::random(10.0));
    }
let len_col: Collection<f64> = col_3v.map(ThreeVec::r);
let histogram: Collection<Bin> = len_col.hist(50);

Trait Implementations§

Source§

impl<T: Clone + Serializable> Clone for Collection<T>

Source§

fn clone(&self) -> Collection<T>

Returns a duplicate 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<T: Debug + Serializable> Debug for Collection<T>

Source§

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

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

impl<T: Serializable + Deserializable> Deserializable for Collection<T>

Source§

fn from_json(s: &str) -> Result<Self, Box<dyn Error>>

Return Self from string
Source§

fn from_msg(bytes: &[u8]) -> Result<(Self, &[u8]), Box<dyn Error>>

Return a tuple of Self and a &u8 of remaining unparsed bytes from a byte array
Source§

impl<T: Serializable> Extend<T> for Collection<T>

Extends a collection by the elements in the provided Iter

§Example

use calcify::FourVec;
use calcify::Collection;

let mut col4V_1: Collection<FourVec> = Collection::empty();
let mut col4V_2: Collection<FourVec> = Collection::empty();
for _i in 0..5000 {
    col4V_1.push(FourVec::new(1.0,0.0,0.0,0.0));
    col4V_2.push(FourVec::new(1.0,0.0,0.0,0.0));
}

col4V_1.extend(col4V_2.into_iter());
assert_eq!(col4V_1.len(),10_000);
Source§

fn extend<U: IntoIterator<Item = T>>(&mut self, iter: U)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<T: Serializable + Clone> From<&[T]> for Collection<T>

Source§

fn from(vec: &[T]) -> Self

Returns new Collection from a &[T: Serializable]

§Arguments
  • vec - &[T: Serializable]
§Example
use calcify::FourVec;
use calcify::Collection;

let a4v = [FourVec::new(10.0,1.0,1.0,1.0)];
let col4V = Collection::from(
    &a4v[..]
);
Source§

impl<T: Serializable> From<Vec<T>> for Collection<T>

Source§

fn from(vec: Vec<T>) -> Self

Returns new Collection from a &[T: Serializable]

§Arguments
  • vec - Vec<T: Serializable>
§Example
use calcify::FourVec;
use calcify::Collection;

let col4V = Collection::from(
    vec![FourVec::new(10.0,1.0,1.0,1.0)]
);
Source§

impl<T: Serializable> FromIterator<T> for Collection<T>

Collects an iterator into a Collection, i.e. provides collect().

§Example

use calcify::FourVec;
use calcify::Collection;

let mut col4V: Collection<FourVec> = Collection::empty();
let mut colf6: Collection<f64> = Collection::empty();
for _i in 0..9999 {
    col4V.push(FourVec::new(1.0,0.0,0.0,0.0));
    colf6.push(1.0);
}

let tCol: Collection<f64> = col4V.into_iter().map(|x| x.s()).collect();

assert_eq!(colf6, tCol);
Source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<T: Serializable> IntoIterator for Collection<T>

Returns the internal Vec iterator

§Example

use calcify::FourVec;
use calcify::Collection;

let mut col4V: Collection<FourVec> = Collection::empty();
for _i in 0..9999 {
    col4V.push(FourVec::new(1.0,0.0,0.0,0.0));
}

assert_eq!(FourVec::new(9999.0,0.0,0.0,0.0),
            col4V.into_iter().fold(FourVec::new(0.0,0.0,0.0,0.0), |acc, x| acc + x));
Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<<Collection<T> as IntoIterator>::Item>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T: PartialEq + Serializable> PartialEq for Collection<T>

Source§

fn eq(&self, other: &Collection<T>) -> 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<T: Serializable> Serializable for Collection<T>

Source§

fn to_json(&self) -> String

Return object intensive json string Read more
Source§

fn to_msg(&self) -> Result<Vec<u8>, ValueWriteError>

Return Result wrapped Vec in MsgPack Format is not like to_json it is array intensive not object Read more
Source§

impl<T: Serializable> StructuralPartialEq for Collection<T>

Auto Trait Implementations§

§

impl<T> Freeze for Collection<T>

§

impl<T> RefUnwindSafe for Collection<T>
where T: RefUnwindSafe,

§

impl<T> Send for Collection<T>
where T: Send,

§

impl<T> Sync for Collection<T>
where T: Sync,

§

impl<T> Unpin for Collection<T>
where T: Unpin,

§

impl<T> UnwindSafe for Collection<T>
where T: 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.