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 via the provided mapping.
§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>where
T: StorageKey,
impl<T> SparseSet<T>where
T: StorageKey,
Sourcepub fn new(input: Vec<T>) -> SparseSet<T>
pub fn new(input: Vec<T>) -> SparseSet<T>
Creates a new SparseSet, using StorageKey::index as the index for the elements.
If StorageKey::index returns the same index for two elements, then this method will
panic.
Source§impl<T> SparseSet<T>
impl<T> SparseSet<T>
Sourcepub fn new_with_mapping(input: Vec<T>, mapping: fn(&T) -> i32) -> SparseSet<T>
pub fn new_with_mapping(input: Vec<T>, mapping: fn(&T) -> i32) -> SparseSet<T>
Creates a new SparseSet, using the provided mapping to map the elements to indices.
If the provided mapping maps two elements in input to the same element then this method
will panic.
For performance, it is recommended to provide a mapping which maps all elements to the
range [0, |domain|].
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.
Note that this method does not check whether the insertion of this element causes clashes in the provided mapping (i.e., it does not check whether two elements are now mapped to the same index).
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> UnsafeUnpin for SparseSet<T>
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>, which can then be
downcast into Box<dyn 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>, which 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> DowncastSend for T
impl<T> DowncastSend for T
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