Struct tari_utilities::fixed_set::FixedSet
source · pub struct FixedSet<T> { /* private fields */ }
Expand description
Data structure for fixed set of size n.
Implementations§
source§impl<T: Clone + PartialEq + Default> FixedSet<T>
impl<T: Clone + PartialEq + Default> FixedSet<T>
sourcepub fn size(&self) -> usize
pub fn size(&self) -> usize
Returns the size of the fixed set, NOT the number of items that have been set.
sourcepub fn set_item(&mut self, index: usize, val: T) -> bool
pub fn set_item(&mut self, index: usize, val: T) -> bool
Set the index
-th item to val
. Any existing item is overwritten. The set takes ownership of val
.
sourcepub fn get_item(&self, index: usize) -> Option<&T>
pub fn get_item(&self, index: usize) -> Option<&T>
Return a reference to the index
-th item, or None
if that item has not been set yet.
sourcepub fn clear_item(&mut self, index: usize)
pub fn clear_item(&mut self, index: usize)
Delete an item from the set by setting the index
-th value to None
.
sourcepub fn is_full(&self) -> bool
pub fn is_full(&self) -> bool
Returns true if every item in the set has been set. An empty set returns true as well.
sourcepub fn search(&self, val: &T) -> Option<usize>
pub fn search(&self, val: &T) -> Option<usize>
Return the first index of the given item in the set by performing a linear search through the set.
sourcepub fn sum(&self) -> Option<T>where
for<'a> &'a T: Add<&'a T, Output = T>,
pub fn sum(&self) -> Option<T>where for<'a> &'a T: Add<&'a T, Output = T>,
Produces the sum of the values in the set, provided the set is full.
Trait Implementations§
Auto Trait Implementations§
impl<T> RefUnwindSafe for FixedSet<T>where T: RefUnwindSafe,
impl<T> Send for FixedSet<T>where T: Send,
impl<T> Sync for FixedSet<T>where T: Sync,
impl<T> Unpin for FixedSet<T>where T: Unpin,
impl<T> UnwindSafe for FixedSet<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