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>
impl<T: Serializable> Collection<T>
Sourcepub fn empty() -> Collection<T>
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();Sourcepub fn at(&mut self, i: usize) -> &mut T
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));Sourcepub fn map<F, Z: Serializable>(&self, close: F) -> Collection<Z>
pub fn map<F, Z: Serializable>(&self, close: F) -> Collection<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);Sourcepub fn cut<F>(&self, close: F) -> Collection<T>
pub fn cut<F>(&self, close: F) -> Collection<T>
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);pub fn len(&self) -> usize
Source§impl Collection<Point>
impl Collection<Point>
Source§impl Collection<f64>
impl Collection<f64>
Sourcepub fn hist(&self, num_bins: u64) -> Collection<Bin>
pub fn hist(&self, num_bins: u64) -> Collection<Bin>
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§
Source§impl<T: Clone + Serializable> Clone for Collection<T>
impl<T: Clone + Serializable> Clone for Collection<T>
Source§fn clone(&self) -> Collection<T>
fn clone(&self) -> Collection<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T: Debug + Serializable> Debug for Collection<T>
impl<T: Debug + Serializable> Debug for Collection<T>
Source§impl<T: Serializable + Deserializable> Deserializable for Collection<T>
impl<T: Serializable + Deserializable> Deserializable for Collection<T>
Source§impl<T: Serializable> Extend<T> for Collection<T>
Extends a collection by the elements in the provided Iter
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)
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)
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)
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>
impl<T: Serializable + Clone> From<&[T]> for Collection<T>
Source§impl<T: Serializable> From<Vec<T>> for Collection<T>
impl<T: Serializable> From<Vec<T>> for Collection<T>
Source§impl<T: Serializable> FromIterator<T> for Collection<T>
Collects an iterator into a Collection, i.e. provides collect().
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
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
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§impl<T: PartialEq + Serializable> PartialEq for Collection<T>
impl<T: PartialEq + Serializable> PartialEq for Collection<T>
Source§impl<T: Serializable> Serializable for Collection<T>
impl<T: Serializable> Serializable for Collection<T>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more