Struct starlark_map::small_set::SmallSet
source · pub struct SmallSet<T>(/* private fields */);
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) -> Self
pub fn with_capacity(n: usize) -> Self
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) -> bool
pub fn insert(&mut self, key: T) -> bool
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,
pub fn insert_unique_unchecked(&mut self, key: T)where
T: Hash,
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>
pub fn get<Q>(&self, value: &Q) -> Option<&T>
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>
pub fn get_hashed<Q>(&self, value: Hashed<&Q>) -> Option<&T>
Query the set by a prehashed value.
sourcepub fn get_index_of<Q>(&self, value: &Q) -> Option<usize>
pub fn get_index_of<Q>(&self, value: &Q) -> Option<usize>
Return item index, if it exists in the set
sourcepub fn get_index_of_hashed<Q>(&self, value: Hashed<&Q>) -> Option<usize>
pub fn get_index_of_hashed<Q>(&self, value: Hashed<&Q>) -> Option<usize>
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) -> bool
pub fn remove<Q>(&mut self, key: &Q) -> bool
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) -> &T
pub fn get_or_insert(&mut self, value: T) -> &T
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) -> &T
pub fn get_or_insert_owned<Q>(&mut self, value: &Q) -> &T
Insert entry if it doesn’t exist.
Return the resulting entry in the map.
sourcepub fn take<Q>(&mut self, key: &Q) -> Option<T>
pub fn take<Q>(&mut self, key: &Q) -> Option<T>
Remove the element from the set if it is present,
and return the removed element.
sourcepub fn contains_hashed<Q>(&self, key: Hashed<&Q>) -> bool
pub fn contains_hashed<Q>(&self, key: Hashed<&Q>) -> bool
Check if the set contains an element.
sourcepub fn difference<'a>(&'a self, other: &'a Self) -> Difference<'a, T> ⓘ
pub fn difference<'a>(&'a self, other: &'a Self) -> Difference<'a, T> ⓘ
Iterator over elements of this set which are not in the other set.
sourcepub fn union<'a>(&'a self, other: &'a Self) -> Union<'a, T> ⓘ
pub fn union<'a>(&'a self, other: &'a Self) -> Union<'a, T> ⓘ
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: &Self) -> boolwhere
T: PartialEq,
pub fn eq_ordered(&self, other: &Self) -> boolwhere
T: PartialEq,
Equal if entries are equal in iteration order.
sourcepub fn hash_ordered<H: Hasher>(&self, state: &mut H)where
T: Hash,
pub fn hash_ordered<H: Hasher>(&self, state: &mut H)where
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> Allocative for SmallSet<T>
impl<T: Allocative> Allocative for SmallSet<T>
source§impl<'de, T> Deserialize<'de> for SmallSet<T>
impl<'de, T> Deserialize<'de> for SmallSet<T>
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
source§impl<T> Extend<T> for SmallSet<T>
impl<T> Extend<T> for SmallSet<T>
source§fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
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
)source§impl<T> From<SmallSet<T>> for OrderedSet<T>
impl<T> From<SmallSet<T>> for OrderedSet<T>
source§fn from(set: SmallSet<T>) -> OrderedSet<T>
fn from(set: SmallSet<T>) -> OrderedSet<T>
source§impl<T> FromIterator<T> for SmallSet<T>
impl<T> FromIterator<T> for SmallSet<T>
source§fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
source§impl<'a, T> IntoIterator for &'a SmallSet<T>
impl<'a, T> IntoIterator for &'a SmallSet<T>
source§impl<T> IntoIterator for SmallSet<T>
impl<T> IntoIterator for SmallSet<T>
source§impl<T> PartialEq for SmallSet<T>where
T: Eq,
impl<T> PartialEq for SmallSet<T>where
T: Eq,
impl<T> Eq for SmallSet<T>where
T: Eq,
Auto Trait Implementations§
impl<T> RefUnwindSafe for SmallSet<T>where
T: RefUnwindSafe,
impl<T> Send for SmallSet<T>where
T: Send,
impl<T> Sync for SmallSet<T>where
T: Sync,
impl<T> Unpin for SmallSet<T>where
T: Unpin,
impl<T> UnwindSafe for SmallSet<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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.