Type Definition utote::MSu32[][src]

type MSu32<const SIZE: usize> = Multiset<u32, SIZE>;

Implementations

impl<const SIZE: usize> MSu32<SIZE>[src]

pub const SIZE: usize[src]

pub const fn empty() -> Self[src]

Returns a Multiset of the given array size with all elements set to zero.

Examples

use utote::MSu8;
let multiset = MSu8::<4>::empty();

pub const fn repeat(elem: u32) -> Self[src]

Returns a Multiset of the given array size with all elements set to elem.

Examples

use utote::MSu8;
let multiset = MSu8::<4>::repeat(5);

pub fn from_slice(slice: &[u32]) -> Self[src]

Returns a Multiset from a slice of the given array size.

Examples

use utote::MSu8;
let multiset = MSu8::<4>::from_slice(&[1, 2, 3, 4]);

pub const fn len() -> usize[src]

The number of elements in the multiset.

Examples

use utote::MSu8;
assert_eq!(MSu8::<4>::len(), 4);

pub fn clear(&mut self)[src]

Sets all element counts in the multiset to zero.

Examples

use utote::MSu8;
let mut multiset = MSu8::<4>::from_slice(&[1, 2, 3, 4]);
multiset.clear();
assert_eq!(multiset.is_empty(), true);

pub fn contains(self, elem: usize) -> bool[src]

Checks that a given element has at least one member in the multiset.

Examples

use utote::MSu8;
let multiset = MSu8::<4>::from_slice(&[1, 2, 0, 0]);
assert_eq!(multiset.contains(1), true);
assert_eq!(multiset.contains(3), false);
assert_eq!(multiset.contains(5), false);

pub unsafe fn contains_unchecked(self, elem: usize) -> bool[src]

Checks that a given element has at least one member in the multiset without bounds checks.

Examples

use utote::MSu8;
let multiset = MSu8::<4>::from_slice(&[1, 2, 0, 0]);
assert_eq!(unsafe { multiset.contains_unchecked(1) }, true);
assert_eq!(unsafe { multiset.contains_unchecked(3) }, false);
// unsafe { multiset.contains_unchecked(5) };  NOT SAFE!!!

Safety

Does not run bounds check on whether this element is an index in the underlying array.

pub fn insert(&mut self, elem: usize, amount: u32)[src]

Set the counter of an element in the multiset to amount.

Examples

use utote::MSu8;
let mut multiset = MSu8::<4>::from_slice(&[1, 2, 0, 0]);
multiset.insert(2, 5);
assert_eq!(multiset.get(2), Some(5));

pub unsafe fn insert_unchecked(&mut self, elem: usize, amount: u32)[src]

Set the counter of an element in the multiset to amount without bounds checks.

Examples

use utote::MSu8;
let mut multiset = MSu8::<4>::from_slice(&[1, 2, 0, 0]);
unsafe { multiset.insert_unchecked(2, 5) };
assert_eq!(multiset.get(2), Some(5));
// unsafe { multiset.insert_unchecked(5, 10) };  NOT SAFE!!!

Safety

Does not run bounds check on whether this element is an index in the underlying array.

pub fn remove(&mut self, elem: usize)[src]

Set the counter of an element in the multiset to zero.

Examples

use utote::MSu8;
let mut multiset = MSu8::<4>::from_slice(&[1, 2, 0, 0]);
multiset.remove(1);
assert_eq!(multiset.get(1), Some(0));

pub unsafe fn remove_unchecked(&mut self, elem: usize)[src]

Set the counter of an element in the multiset to zero without bounds checks.

Examples

use utote::MSu8;
let mut multiset = MSu8::<4>::from_slice(&[1, 2, 0, 0]);
unsafe { multiset.remove_unchecked(1) };
assert_eq!(multiset.get(1), Some(0));
// unsafe { multiset.remove_unchecked(5) };  NOT SAFE!!!

Safety

Does not run bounds check on whether this element is an index in the underlying array.

pub fn get(self, elem: usize) -> Option<u32>[src]

Returns the amount of an element in the multiset.

Examples

use utote::MSu8;
let multiset = MSu8::<4>::from_slice(&[1, 2, 0, 0]);
assert_eq!(multiset.get(1), Some(2));
assert_eq!(multiset.get(3), Some(0));
assert_eq!(multiset.get(5), None);

pub unsafe fn get_unchecked(self, elem: usize) -> u32[src]

Returns the amount of an element in the multiset without bounds checks.

Examples

use utote::MSu8;
let multiset = MSu8::<4>::from_slice(&[1, 2, 0, 0]);
assert_eq!(unsafe { multiset.get_unchecked(1) }, 2);
assert_eq!(unsafe { multiset.get_unchecked(3) }, 0);
// unsafe { multiset.get_unchecked(5) };  NOT SAFE!!!

Safety

Does not run bounds check on whether this element is an index in the underlying array.

pub fn intersection(&self, other: &Self) -> Self[src]

Returns a multiset which is the intersection of self and other.

The Intersection of two multisets A & B is defined as the multiset C where C[0] == min(A[0], B[0]).

Examples

use utote::MSu8;
let a = MSu8::<4>::from_slice(&[1, 2, 0, 0]);
let b = MSu8::<4>::from_slice(&[0, 2, 3, 0]);
let c = MSu8::<4>::from_slice(&[0, 2, 0, 0]);
assert_eq!(a.intersection(&b), c);

pub fn union(&self, other: &Self) -> Self[src]

Returns a multiset which is the union of self and other.

The union of two multisets A & B is defined as the multiset C where C[0] == max(A[0], B[0]).

Examples

use utote::MSu8;
let a = MSu8::<4>::from_slice(&[1, 2, 0, 0]);
let b = MSu8::<4>::from_slice(&[0, 2, 3, 0]);
let c = MSu8::<4>::from_slice(&[1, 2, 3, 0]);
assert_eq!(a.union(&b), c);

pub fn count_zero(&self) -> u32[src]

Return the number of elements whose counter is zero.

Examples

use utote::MSu8;
let multiset = MSu8::<4>::from_slice(&[1, 0, 0, 0]);
assert_eq!(multiset.count_zero(), 3);

pub fn count_non_zero(&self) -> u32[src]

Return the number of elements whose counter is non-zero.

Examples

use utote::MSu8;
let multiset = MSu8::<4>::from_slice(&[1, 0, 0, 0]);
assert_eq!(multiset.count_non_zero(), 1);

pub fn is_empty(&self) -> bool[src]

Check whether all elements have a count of zero.

Examples

use utote::MSu8;
let multiset = MSu8::<4>::from_slice(&[0, 0, 0, 0]);
assert_eq!(multiset.is_empty(), true);
assert_eq!(MSu8::<4>::empty().is_empty(), true);

pub fn is_singleton(&self) -> bool[src]

Check whether only one element has a non-zero count.

Examples

use utote::MSu8;
let multiset = MSu8::<4>::from_slice(&[0, 5, 0, 0]);
assert_eq!(multiset.is_singleton(), true);

pub fn is_disjoint(&self, other: &Self) -> bool[src]

Returns true if self has no elements in common with other.

Examples

use utote::MSu8;
let a = MSu8::<4>::from_slice(&[1, 2, 0, 0]);
let b = MSu8::<4>::from_slice(&[0, 0, 3, 4]);
assert_eq!(a.is_disjoint(&a), false);
assert_eq!(a.is_disjoint(&b), true);

pub fn is_subset(&self, other: &Self) -> bool[src]

Check whether self is a subset of other.

Multiset A is a subset of B if A[i] <= B[i] for all i in A.

Examples

use utote::MSu8;
let a = MSu8::<4>::from_slice(&[1, 2, 0, 0]);
let b = MSu8::<4>::from_slice(&[1, 3, 0, 0]);
assert_eq!(a.is_subset(&a), true);
assert_eq!(a.is_subset(&b), true);

pub fn is_superset(&self, other: &Self) -> bool[src]

Check whether self is a superset of other.

Multiset A is a superset of B if A[i] >= B[i] for all i in A.

Examples

use utote::MSu8;
let a = MSu8::<4>::from_slice(&[1, 2, 0, 0]);
let b = MSu8::<4>::from_slice(&[1, 1, 0, 0]);
assert_eq!(a.is_superset(&a), true);
assert_eq!(a.is_superset(&b), true);

pub fn is_proper_subset(&self, other: &Self) -> bool[src]

Check whether self is a proper subset of other.

Multiset A is a proper subset of B if A[i] <= B[i] for all i in A and there exists j such that A[j] < B[j].

Examples

use utote::MSu8;
let a = MSu8::<4>::from_slice(&[1, 2, 0, 0]);
let b = MSu8::<4>::from_slice(&[1, 3, 0, 0]);
assert_eq!(a.is_proper_subset(&a), false);
assert_eq!(a.is_proper_subset(&b), true);

pub fn is_proper_superset(&self, other: &Self) -> bool[src]

Check whether self is a proper superset of other.

Multiset A is a proper superset of B if A[i] >= B[i] for all i in A and there exists j such that A[j] > B[j].

Examples

use utote::MSu8;
let a = MSu8::<4>::from_slice(&[1, 2, 0, 0]);
let b = MSu8::<4>::from_slice(&[1, 1, 0, 0]);
assert_eq!(a.is_proper_superset(&a), false);
assert_eq!(a.is_proper_superset(&b), true);

pub fn is_any_lesser(&self, other: &Self) -> bool[src]

Check whether any element of self is less than an element of other.

True if the exists some i such that A[i] < B[i].

Examples

use utote::MSu8;
let a = MSu8::<4>::from_slice(&[1, 2, 4, 0]);
let b = MSu8::<4>::from_slice(&[1, 3, 0, 0]);
assert_eq!(a.is_any_lesser(&a), false);
assert_eq!(a.is_any_lesser(&b), true);

pub fn is_any_greater(&self, other: &Self) -> bool[src]

Check whether any element of self is greater than an element of other.

True if the exists some i such that A[i] > B[i].

Examples

use utote::MSu8;
let a = MSu8::<4>::from_slice(&[1, 2, 0, 0]);
let b = MSu8::<4>::from_slice(&[1, 1, 4, 0]);
assert_eq!(a.is_any_greater(&a), false);
assert_eq!(a.is_any_greater(&b), true);

pub fn total(&self) -> u32[src]

The total or cardinality of a multiset is the sum of all its elements member counts.

Examples

use utote::MSu8;
let multiset = MSu8::<4>::from_slice(&[1, 2, 3, 4]);
assert_eq!(multiset.total(), 10);

Notes:

  • This may overflow.

pub fn argmax(&self) -> (usize, u32)[src]

Returns a tuple containing the (element, corresponding largest counter) in the multiset.

Examples

use utote::MSu8;
let multiset = MSu8::<4>::from_slice(&[2, 0, 5, 3]);
assert_eq!(multiset.argmax(), (2, 5));

pub fn imax(&self) -> usize[src]

Returns the element with the largest count in the multiset.

Examples

use utote::MSu8;
let multiset = MSu8::<4>::from_slice(&[2, 0, 5, 3]);
assert_eq!(multiset.imax(), 2);

pub fn max(&self) -> u32[src]

Returns the largest counter in the multiset.

Examples

use utote::MSu8;
let multiset = MSu8::<4>::from_slice(&[2, 0, 5, 3]);
assert_eq!(multiset.max(), 5);

pub fn argmin(&self) -> (usize, u32)[src]

Returns a tuple containing the (element, corresponding smallest counter) in the multiset.

Examples

use utote::MSu8;
let multiset = MSu8::<4>::from_slice(&[2, 0, 5, 3]);
assert_eq!(multiset.argmin(), (1, 0));

pub fn imin(&self) -> usize[src]

Returns the element with the smallest count in the multiset.

Examples

use utote::MSu8;
let multiset = MSu8::<4>::from_slice(&[2, 0, 5, 3]);
assert_eq!(multiset.imin(), 1);

pub fn min(&self) -> u32[src]

Returns the smallest counter in the multiset.

Examples

use utote::MSu8;
let multiset = MSu8::<4>::from_slice(&[2, 0, 5, 3]);
assert_eq!(multiset.min(), 0);

pub fn choose(&mut self, elem: usize)[src]

Set all element counts, except for the given elem, to zero.

Examples

use utote::MSu8;
let mut multiset = MSu8::<4>::from_slice(&[2, 0, 5, 3]);
multiset.choose(2);
let result = MSu8::<4>::from_slice(&[0, 0, 5, 0]);
assert_eq!(multiset, result);

pub fn choose_random<T: RngCore>(&mut self, rng: &mut T)[src]

Set all element counts, except for a random choice, to zero. The choice is weighted by the counts of the elements.

Examples

use utote::MSu8;
use rand::prelude::*;
let rng = &mut SmallRng::seed_from_u64(thread_rng().next_u64());
let mut multiset = MSu8::<4>::from_slice(&[2, 0, 5, 3]);
multiset.choose_random(rng);
assert_eq!(multiset.is_singleton(), true);

impl<const SIZE: usize> MSu32<SIZE> where
    f64: From<u32>, 
[src]

pub fn collision_entropy(&self) -> f64[src]

Calculate the collision entropy of the multiset.

Examples

use utote::MSu8;
let multiset = MSu8::<4>::from_slice(&[2, 1, 1, 0]);
let result = multiset.collision_entropy();
// approximate: result == 1.415037499278844

pub fn shannon_entropy(&self) -> f64[src]

Calculate the shannon entropy of the multiset. Uses ln rather than log2.

Examples

use utote::MSu8;
let multiset = MSu8::<4>::from_slice(&[2, 1, 1, 0]);
let result = multiset.shannon_entropy();
// approximate: result == 1.0397207708399179

Trait Implementations

impl<'a, const SIZE: usize> FromIterator<&'a u32> for MSu32<SIZE>[src]

impl<const SIZE: usize> FromIterator<u32> for MSu32<SIZE>[src]

impl<const SIZE: usize> IntoIterator for MSu32<SIZE>[src]

type Item = u32

The type of the elements being iterated over.

type IntoIter = MultisetIterator<u32, SIZE>

Which kind of iterator are we turning this into?

impl<const SIZE: usize> PartialOrd<Multiset<u32, SIZE>> for MSu32<SIZE>[src]