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

Returns new Collection from a Vec<T: Serializable>

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

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

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

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

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

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

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

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

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Return Self from string

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

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

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

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

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[..]
);

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

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

Creates a value from an iterator. Read more

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

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Return object intensive json string Read more

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.