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>

source

pub fn new(n: usize) -> FixedSet<T>

Creates a new fixed set of size n.

source

pub fn size(&self) -> usize

Returns the size of the fixed set, NOT the number of items that have been set.

source

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.

source

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.

source

pub fn clear_item(&mut self, index: usize)

Delete an item from the set by setting the index-th value to None.

source

pub fn is_full(&self) -> bool

Returns true if every item in the set has been set. An empty set returns true as well.

source

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.

source

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.

source

pub fn into_vec(self) -> Vec<T>

Collects all non-empty elements of the set into a Vec instance.

source

pub fn iter(&self) -> impl Iterator<Item = Option<&T>> + '_

Returns an iterator that yields exactly n elements of the FixedSet. An element may be not be set which yields a None.

Trait Implementations§

source§

impl<T: Clone> Clone for FixedSet<T>

source§

fn clone(&self) -> FixedSet<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for FixedSet<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.