Struct starlark::collections::SmallSet
source · pub struct SmallSet<T>(_);
Expand description
An memory-efficient set with deterministic order, based on SmallMap
.
Implementations§
source§impl<T> SmallSet<T>
impl<T> SmallSet<T>
sourcepub fn with_capacity(n: usize) -> SmallSet<T>
pub fn with_capacity(n: usize) -> SmallSet<T>
Empty small set with preallocated capacity.
sourcepub fn iter_hashed(&self) -> IterHashed<'_, T>
pub fn iter_hashed(&self) -> IterHashed<'_, T>
Iterate the hashed element references.
sourcepub fn iter_mut_unchecked(&mut self) -> IterMutUnchecked<'_, T>
pub fn iter_mut_unchecked(&mut self) -> IterMutUnchecked<'_, T>
Iterate the mutable element references.
This operation is memory safe, but otherwise no guarantees if keys are mutated inconsistently (hash or equality changes).
sourcepub fn into_iter_hashed(self) -> IntoIterHashed<T>
pub fn into_iter_hashed(self) -> IntoIterHashed<T>
Into hashed entries.
sourcepub fn insert(&mut self, key: T) -> boolwhere
T: Hash + Eq,
pub fn insert(&mut self, key: T) -> boolwhere T: Hash + Eq,
Insert the element into the set.
Return true
iff the element was inserted.
sourcepub fn insert_unique_unchecked(&mut self, key: T)where
T: Hash + Eq,
pub fn insert_unique_unchecked(&mut self, key: T)where T: Hash + Eq,
Insert the element into the set without checking for a duplicate entry.
sourcepub fn insert_hashed(&mut self, key: Hashed<T>) -> boolwhere
T: Eq,
pub fn insert_hashed(&mut self, key: Hashed<T>) -> boolwhere T: Eq,
Insert the element into the set.
Return true
iff the element was inserted.
sourcepub fn insert_hashed_unique_unchecked(&mut self, key: Hashed<T>)
pub fn insert_hashed_unique_unchecked(&mut self, key: Hashed<T>)
Insert an entry into the set without checking for a duplicate key.
sourcepub fn get<Q>(&self, value: &Q) -> Option<&T>where
Q: Hash + Equivalent<T> + ?Sized,
T: Eq,
pub fn get<Q>(&self, value: &Q) -> Option<&T>where Q: Hash + Equivalent<T> + ?Sized, T: Eq,
Return a reference to the value stored in the set, if it is present,
else None
.
Computes in O(1) time (average).
sourcepub fn get_hashed<Q>(&self, value: Hashed<&Q>) -> Option<&T>where
Q: Equivalent<T> + ?Sized,
T: Eq,
pub fn get_hashed<Q>(&self, value: Hashed<&Q>) -> Option<&T>where Q: Equivalent<T> + ?Sized, T: Eq,
Query the set by a prehashed value.
sourcepub fn get_index_of<Q>(&self, value: &Q) -> Option<usize>where
Q: Hash + Equivalent<T> + ?Sized,
T: Eq,
pub fn get_index_of<Q>(&self, value: &Q) -> Option<usize>where Q: Hash + Equivalent<T> + ?Sized, T: Eq,
Return item index, if it exists in the set
sourcepub fn get_index_of_hashed<Q>(&self, value: Hashed<&Q>) -> Option<usize>where
Q: Equivalent<T> + ?Sized,
T: Eq,
pub fn get_index_of_hashed<Q>(&self, value: Hashed<&Q>) -> Option<usize>where Q: Equivalent<T> + ?Sized, T: Eq,
Find the index of the given hashed value.
sourcepub fn get_index_of_hashed_by_value<Q>(&self, value: Hashed<Q>) -> Option<usize>where
Q: Equivalent<T>,
T: Eq,
pub fn get_index_of_hashed_by_value<Q>(&self, value: Hashed<Q>) -> Option<usize>where Q: Equivalent<T>, T: Eq,
Find the index of the given hashed value.
This operations is similar to get_index_of_hashed
,
but it takes the key by value, instead of by reference
which sometimes generates better code.
sourcepub fn remove<Q>(&mut self, key: &Q) -> boolwhere
Q: Hash + Equivalent<T> + ?Sized,
T: Eq,
pub fn remove<Q>(&mut self, key: &Q) -> boolwhere Q: Hash + Equivalent<T> + ?Sized, T: Eq,
Remove the element from the set if it is present.
Time complexity of this operation is O(N) where N is the number of entries in the set.
sourcepub fn get_or_insert(&mut self, value: T) -> &Twhere
T: Hash + Eq,
pub fn get_or_insert(&mut self, value: T) -> &Twhere T: Hash + Eq,
Insert entry if it doesn’t exist.
Return the resulting entry in the map.
sourcepub fn get_or_insert_owned<Q>(&mut self, value: &Q) -> &Twhere
Q: Hash + Equivalent<T> + ToOwned<Owned = T> + ?Sized,
T: Eq,
pub fn get_or_insert_owned<Q>(&mut self, value: &Q) -> &Twhere Q: Hash + Equivalent<T> + ToOwned<Owned = T> + ?Sized, T: Eq,
Insert entry if it doesn’t exist.
Return the resulting entry in the map.
sourcepub fn take<Q>(&mut self, key: &Q) -> Option<T>where
Q: Hash + Equivalent<T> + ?Sized,
T: Eq,
pub fn take<Q>(&mut self, key: &Q) -> Option<T>where Q: Hash + Equivalent<T> + ?Sized, T: Eq,
Remove the element from the set if it is present,
and return the removed element.
sourcepub fn contains<Q>(&self, key: &Q) -> boolwhere
Q: Hash + Equivalent<T> + ?Sized,
T: Eq,
pub fn contains<Q>(&self, key: &Q) -> boolwhere Q: Hash + Equivalent<T> + ?Sized, T: Eq,
Check if the set contains an element.
sourcepub fn contains_hashed<Q>(&self, key: Hashed<&Q>) -> boolwhere
Q: Equivalent<T> + ?Sized,
T: Eq,
pub fn contains_hashed<Q>(&self, key: Hashed<&Q>) -> boolwhere Q: Equivalent<T> + ?Sized, T: Eq,
Check if the set contains an element.
sourcepub fn difference<'a>(&'a self, other: &'a SmallSet<T>) -> Difference<'a, T>where
T: Eq + Hash,
pub fn difference<'a>(&'a self, other: &'a SmallSet<T>) -> Difference<'a, T>where T: Eq + Hash,
Iterator over elements of this set which are not in the other set.
sourcepub fn union<'a>(&'a self, other: &'a SmallSet<T>) -> Union<'a, T>where
T: Eq + Hash,
pub fn union<'a>(&'a self, other: &'a SmallSet<T>) -> Union<'a, T>where T: Eq + Hash,
Iterator over union of two sets.
Iteration order is: elements of this set followed by elements in the other set not present in this set.
sourcepub fn eq_ordered(&self, other: &SmallSet<T>) -> boolwhere
T: PartialEq<T>,
pub fn eq_ordered(&self, other: &SmallSet<T>) -> boolwhere T: PartialEq<T>,
Equal if entries are equal in iteration order.
sourcepub fn hash_ordered<H>(&self, state: &mut H)where
H: Hasher,
T: Hash,
pub fn hash_ordered<H>(&self, state: &mut H)where H: Hasher, T: Hash,
Hash entries in iteration order.
Note, entries are not hashed, but previously computed hashes are hashed instead.
Trait Implementations§
source§impl<T> Allocative for SmallSet<T>where
T: Allocative,
impl<T> Allocative for SmallSet<T>where T: Allocative,
source§impl<'de, T> Deserialize<'de> for SmallSet<T>where
T: Deserialize<'de> + Hash + Eq,
impl<'de, T> Deserialize<'de> for SmallSet<T>where T: Deserialize<'de> + Hash + Eq,
source§fn deserialize<D>(
deserializer: D
) -> Result<SmallSet<T>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>( deserializer: D ) -> Result<SmallSet<T>, <D as Deserializer<'de>>::Error>where D: Deserializer<'de>,
source§impl<T> Extend<T> for SmallSet<T>where
T: Eq + Hash,
impl<T> Extend<T> for SmallSet<T>where T: Eq + Hash,
source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = T>,
fn extend<I>(&mut self, iter: I)where I: IntoIterator<Item = T>,
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)