pub struct Partition { /* private fields */ }
Implementations§
source§impl Partition
impl Partition
pub fn new_unchecked(z: Vec<usize>, counts: Vec<usize>) -> Self
pub fn z(&self) -> &Vec<usize>
pub fn z_mut(&mut self) -> &mut Vec<usize>
pub fn counts(&self) -> &Vec<usize>
pub fn counts_mut(&mut self) -> &mut Vec<usize>
sourcepub fn from_z(z: Vec<usize>) -> Result<Self, PartitionError>
pub fn from_z(z: Vec<usize>) -> Result<Self, PartitionError>
Create a Partition
with a given assignment, z
Examples
let z1 = vec![0, 1, 2, 3, 1, 2];
let part = Partition::from_z(z1).unwrap();
assert_eq!(*part.z(), vec![0, 1, 2, 3, 1, 2]);
assert_eq!(*part.counts(), vec![1, 2, 2, 1]);
// Invalid z because k=4 is empty. All partitions must be occupied.
let z2 = vec![0, 1, 2, 3, 1, 5];
assert!(Partition::from_z(z2).is_err());
sourcepub fn remove(&mut self, ix: usize) -> Result<(), PartitionError>
pub fn remove(&mut self, ix: usize) -> Result<(), PartitionError>
Remove the item at index ix
Example
let mut part = Partition::from_z(vec![0, 1, 0, 2]).unwrap();
part.remove(1).expect("Could not remove");
assert_eq!(*part.z(), vec![0, 0, 1]);
assert_eq!(*part.counts(), vec![2, 1]);
sourcepub fn append(&mut self, zi: usize) -> Result<(), PartitionError>
pub fn append(&mut self, zi: usize) -> Result<(), PartitionError>
Append a new item assigned to partition zi
Example
let mut part = Partition::from_z(vec![0, 1, 0, 2]).unwrap();
part.append(3).expect("Could not append");
assert_eq!(*part.z(), vec![0, 1, 0, 2, 3]);
assert_eq!(*part.counts(), vec![2, 1, 1, 1]);
sourcepub fn k(&self) -> usize
pub fn k(&self) -> usize
Returns the number of partitions, k.
Example
let part = Partition::from_z(vec![0, 1, 0, 2]).unwrap();
assert_eq!(part.k(), 3);
assert_eq!(*part.counts(), vec![2, 1, 1]);
pub fn is_empty(&self) -> bool
Trait Implementations§
source§impl<'de> Deserialize<'de> for Partition
impl<'de> Deserialize<'de> for Partition
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl PartialEq<Partition> for Partition
impl PartialEq<Partition> for Partition
impl Eq for Partition
impl StructuralEq for Partition
impl StructuralPartialEq for Partition
Auto Trait Implementations§
impl RefUnwindSafe for Partition
impl Send for Partition
impl Sync for Partition
impl Unpin for Partition
impl UnwindSafe for Partition
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
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.