Trait array_tool::vec::Uniq
[−]
[src]
pub trait Uniq<T> { fn uniq(&self, other: Self) -> Self; fn unique(&self) -> Self; fn is_unique(&self) -> bool; fn uniq_via<F: Fn(&T, &T) -> bool>(&self, other: Self, f: F) -> Self; fn unique_via<F: Fn(&T, &T) -> bool>(&self, f: F) -> Self; fn is_unique_via<F: Fn(&T, &T) -> bool>(&self, f: F) -> bool; }
Several different methods for getting, or evaluating, uniqueness.
Required Methods
fn uniq(&self, other: Self) -> Self
uniq
returns a vector of unique values within itself as compared to
the other vector which is provided as an input parameter.
Example
use array_tool::vec::Uniq; vec![1,2,3,4,5,6].uniq( vec![1,2,5,7,9] );
Output
vec![3,4,6]
fn unique(&self) -> Self
unique
removes duplicates from within the vector and returns Self.
Example
use array_tool::vec::Uniq; vec![1,2,1,3,2,3,4,5,6].unique();
Output
vec![1,2,3,4,5,6]
fn is_unique(&self) -> bool
is_unique
returns boolean value on whether all values within
Self are unique.
Example
use array_tool::vec::Uniq; vec![1,2,1,3,4,3,4,5,6].is_unique();
Output
false
fn uniq_via<F: Fn(&T, &T) -> bool>(&self, other: Self, f: F) -> Self
uniq_via
returns a vector of unique values within itself as compared to
the other vector which is provided as an input parameter, as defined by a
provided custom comparator.
Example
use array_tool::vec::Uniq; vec![1,2,3,4,5,6].uniq_via( vec![1,2,5,7,9], |&l, r| l == r + 2 );
Output
vec![1,2,4,6]
fn unique_via<F: Fn(&T, &T) -> bool>(&self, f: F) -> Self
unique_via
removes duplicates, as defined by a provided custom comparator,
from within the vector and returns Self.
Example
use array_tool::vec::Uniq; vec![1.0,2.0,1.4,3.3,2.1,3.5,4.6,5.2,6.2].unique_via( |l: &f64, r: &f64| l.floor() == r.floor() );
Output
vec![1.0,2.0,3.3,4.6,5.2,6.2]