pub struct SparseSet<T> { /* private fields */ }Expand description
A set for keeping track of which values are still part of the original domain based on [1]. See the module level documentation for more information.
It provides O(1) removals of values from the domain and O(|D|) traversal of the domain (where D are the values which are currently in the domain).
Note that it is required that each element contained in the domain can be uniquely mapped to an index in the range [0, |D|) (i.e. the mapping function is bijective)
§Bibliography
[1] V. le C. de Saint-Marcq, P. Schaus, C. Solnon, and C. Lecoutre, ‘Sparse-sets for domain implementation’, in CP workshop on Techniques foR Implementing Constraint programming Systems (TRICS), 2013, pp. 1–10.
Implementations§
Source§impl<T> SparseSet<T>
impl<T> SparseSet<T>
Sourcepub fn new(input: Vec<T>, mapping: fn(&T) -> usize) -> SparseSet<T>
pub fn new(input: Vec<T>, mapping: fn(&T) -> usize) -> SparseSet<T>
Assumption: It is assumed that mapping is a bijective function which
will return an index which is in the range [0, |D_{original}|) (where D_{original} is
the initial domain before any operations have been performed).
pub fn set_to_empty(&mut self)
pub fn restore_temporarily_removed(&mut self)
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Determines whether the domain represented by the SparseSet is empty
Sourcepub fn get(&self, index: usize) -> &T
pub fn get(&self, index: usize) -> &T
Returns the indexth element in the domain; if index is larger than or equal to
SparseSet::len then this method will panic.
Sourcepub fn remove(&mut self, to_remove: &T)
pub fn remove(&mut self, to_remove: &T)
Remove the value of to_remove from the domain; if the value is not in the domain then this
method does not perform any operations.
pub fn remove_temporarily(&mut self, to_remove: &T)
Sourcepub fn contains(&self, element: &T) -> bool
pub fn contains(&self, element: &T) -> bool
Determines whehter the element is contained in the domain of the sparse-set.
Sourcepub fn accommodate(&mut self, element: &T)
pub fn accommodate(&mut self, element: &T)
Accomodates the element.
Sourcepub fn insert(&mut self, element: T)
pub fn insert(&mut self, element: T)
Inserts the element if it is not already contained in the sparse set.
Sourcepub fn iter(&self) -> impl Iterator<Item = &T>
pub fn iter(&self) -> impl Iterator<Item = &T>
Returns an iterator which goes over the values in the domain of the sparse-set
pub fn out_of_domain(&self) -> impl Iterator<Item = &T>
Trait Implementations§
Source§impl<T> IntoIterator for SparseSet<T>
impl<T> IntoIterator for SparseSet<T>
Auto Trait Implementations§
impl<T> Freeze for SparseSet<T>
impl<T> RefUnwindSafe for SparseSet<T>where
T: RefUnwindSafe,
impl<T> Send for SparseSet<T>where
T: Send,
impl<T> Sync for SparseSet<T>where
T: Sync,
impl<T> Unpin for SparseSet<T>where
T: Unpin,
impl<T> UnwindSafe for SparseSet<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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more