Struct calcify::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
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));
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
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
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
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
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));
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.
Auto Trait Implementations
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
Mutably borrows from an owned value. Read more