Skip to main content

SparseSet

Struct SparseSet 

Source
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>

Source

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).

Source

pub fn set_to_empty(&mut self)

Source

pub fn restore_temporarily_removed(&mut self)

Source

pub fn is_empty(&self) -> bool

Determines whether the domain represented by the SparseSet is empty

Source

pub fn len(&self) -> usize

Returns how many elements are part of the domain

Source

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.

Source

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.

Source

pub fn remove_temporarily(&mut self, to_remove: &T)

Source

pub fn contains(&self, element: &T) -> bool

Determines whehter the element is contained in the domain of the sparse-set.

Source

pub fn accommodate(&mut self, element: &T)

Accomodates the element.

Source

pub fn insert(&mut self, element: T)

Inserts the element if it is not already contained in the sparse set.

Source

pub fn iter(&self) -> impl Iterator<Item = &T>

Returns an iterator which goes over the values in the domain of the sparse-set

Source

pub fn out_of_domain(&self) -> impl Iterator<Item = &T>

Trait Implementations§

Source§

impl<T> Clone for SparseSet<T>
where T: Clone,

Source§

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

Returns a duplicate 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 for SparseSet<T>
where T: Debug,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T> IntoIterator for SparseSet<T>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = Take<IntoIter<T>>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <SparseSet<T> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V