pub struct LinkedHashSet<T, S = RandomState> { /* private fields */ }Expand description
A hash set that preserves insertion order and exposes a
VecDeque-like API with insert_back, insert_front,
[pop_front], and [pop_back].
Implemented as a thin wrapper around LinkedHashMap<T, ()>.
Elements require only Hash + Eq. They do not need to be
Clone or Copy — including heap-owning types such as String,
Vec<T>, or Box<T>.
§Ordering contract
insert_back and insert_front on an element that already exists
are a no-op - the element keeps its current position. Use
move_to_back / move_to_front to explicitly reorder an element.
§Example
use linked_hash_table::LinkedHashSet;
let mut s = LinkedHashSet::new();
s.insert_back("a");
s.insert_back("b");
s.insert_back("c");
assert_eq!(s.pop_front(), Some("a"));
assert_eq!(s.pop_back(), Some("c"));Implementations§
Source§impl<T> LinkedHashSet<T>
impl<T> LinkedHashSet<T>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates an empty LinkedHashSet with the specified initial capacity.
Source§impl<T, S> LinkedHashSet<T, S>
impl<T, S> LinkedHashSet<T, S>
Sourcepub fn with_hasher(hash_builder: S) -> Self
pub fn with_hasher(hash_builder: S) -> Self
Creates an empty LinkedHashSet using the supplied hasher builder.
Sourcepub fn with_capacity_and_hasher(capacity: usize, hash_builder: S) -> Self
pub fn with_capacity_and_hasher(capacity: usize, hash_builder: S) -> Self
Creates an empty LinkedHashSet with the given capacity and hasher.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of elements the set can hold without reallocating.
Sourcepub fn hasher(&self) -> &S
pub fn hasher(&self) -> &S
Returns a reference to the set’s BuildHasher.
Source§impl<T, S> LinkedHashSet<T, S>
impl<T, S> LinkedHashSet<T, S>
Sourcepub fn insert_back(&mut self, value: T) -> bool
pub fn insert_back(&mut self, value: T) -> bool
Inserts value at the back (most-recently-inserted end).
Returns true if the value was newly inserted. If the value already
exists its position is preserved (no-op) and false is returned.
Sourcepub fn insert_front(&mut self, value: T) -> bool
pub fn insert_front(&mut self, value: T) -> bool
Inserts value at the front (least-recently-inserted end).
Returns true if the value was newly inserted. If the value already
exists its position is preserved (no-op) and false is returned.
Sourcepub fn insert(&mut self, value: T) -> bool
pub fn insert(&mut self, value: T) -> bool
Alias for insert_back - matches the HashSet::insert signature.
Sourcepub fn get<Q>(&self, value: &Q) -> Option<&T>
pub fn get<Q>(&self, value: &Q) -> Option<&T>
Returns a reference to the element in the set that equals value,
or None if it is not present.
Sourcepub fn front(&self) -> Option<&T>
pub fn front(&self) -> Option<&T>
Returns a reference to the front (oldest) element, or None if
the set is empty.
Sourcepub fn back(&self) -> Option<&T>
pub fn back(&self) -> Option<&T>
Returns a reference to the back (most recently inserted) element,
or None if the set is empty.
Sourcepub fn pop_front(&mut self) -> Option<T>
pub fn pop_front(&mut self) -> Option<T>
Removes and returns the front (oldest) element, or None.
Sourcepub fn pop_back(&mut self) -> Option<T>
pub fn pop_back(&mut self) -> Option<T>
Removes and returns the back (newest) element, or None.
Sourcepub fn remove<Q>(&mut self, value: &Q) -> bool
pub fn remove<Q>(&mut self, value: &Q) -> bool
Removes value from the set.
Returns true if the element was present.
Sourcepub fn take<Q>(&mut self, value: &Q) -> Option<T>
pub fn take<Q>(&mut self, value: &Q) -> Option<T>
Removes the element equal to value and returns it, if present.
Sourcepub fn retain<F>(&mut self, f: F)
pub fn retain<F>(&mut self, f: F)
Retains only the elements for which f returns true.
Elements are visited in insertion order (front → back).
Sourcepub fn move_to_back<Q>(&mut self, value: &Q) -> bool
pub fn move_to_back<Q>(&mut self, value: &Q) -> bool
Moves value to the back of the ordering.
Returns true if the element was found.
Sourcepub fn move_to_front<Q>(&mut self, value: &Q) -> bool
pub fn move_to_front<Q>(&mut self, value: &Q) -> bool
Moves value to the front of the ordering.
Returns true if the element was found.
Sourcepub fn drain(&mut self) -> SetDrain<'_, T> ⓘ
pub fn drain(&mut self) -> SetDrain<'_, T> ⓘ
Removes all elements in insertion order, returning them via an iterator. The set is empty after this call (even if the iterator is dropped before it is fully consumed).
Sourcepub fn is_subset<S2: BuildHasher>(&self, other: &LinkedHashSet<T, S2>) -> bool
pub fn is_subset<S2: BuildHasher>(&self, other: &LinkedHashSet<T, S2>) -> bool
Returns true if every element of self is also contained in other.
Sourcepub fn is_superset<S2: BuildHasher>(&self, other: &LinkedHashSet<T, S2>) -> bool
pub fn is_superset<S2: BuildHasher>(&self, other: &LinkedHashSet<T, S2>) -> bool
Returns true if every element of other is also contained in self.
Sourcepub fn is_disjoint<S2: BuildHasher>(&self, other: &LinkedHashSet<T, S2>) -> bool
pub fn is_disjoint<S2: BuildHasher>(&self, other: &LinkedHashSet<T, S2>) -> bool
Returns true if self and other share no elements.
Trait Implementations§
Source§impl<T: Clone + Hash + Eq, S: BuildHasher + Clone> Clone for LinkedHashSet<T, S>
impl<T: Clone + Hash + Eq, S: BuildHasher + Clone> Clone for LinkedHashSet<T, S>
Source§impl<T: Debug, S> Debug for LinkedHashSet<T, S>
impl<T: Debug, S> Debug for LinkedHashSet<T, S>
Source§impl<T> Default for LinkedHashSet<T>
impl<T> Default for LinkedHashSet<T>
Source§impl<T: Hash + Eq, S: BuildHasher> Extend<T> for LinkedHashSet<T, S>
impl<T: Hash + Eq, S: BuildHasher> Extend<T> for LinkedHashSet<T, S>
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: Hash + Eq> FromIterator<T> for LinkedHashSet<T>
impl<T: Hash + Eq> FromIterator<T> for LinkedHashSet<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, S> IntoIterator for &'a LinkedHashSet<T, S>
Shared-reference iterator: yields &T in insertion order.
impl<'a, T, S> IntoIterator for &'a LinkedHashSet<T, S>
Shared-reference iterator: yields &T in insertion order.
Source§impl<T, S> IntoIterator for LinkedHashSet<T, S>
Consuming iterator: yields all elements in insertion order.
impl<T, S> IntoIterator for LinkedHashSet<T, S>
Consuming iterator: yields all elements in insertion order.
Source§impl<T: PartialEq, S1, S2> PartialEq<LinkedHashSet<T, S2>> for LinkedHashSet<T, S1>
impl<T: PartialEq, S1, S2> PartialEq<LinkedHashSet<T, S2>> for LinkedHashSet<T, S1>
Source§fn eq(&self, other: &LinkedHashSet<T, S2>) -> bool
fn eq(&self, other: &LinkedHashSet<T, S2>) -> bool
Two sets are equal only when they contain the same elements in the same order.
impl<T: PartialEq + Eq, S> Eq for LinkedHashSet<T, S>
Auto Trait Implementations§
impl<T, S> Freeze for LinkedHashSet<T, S>where
S: Freeze,
impl<T, S> RefUnwindSafe for LinkedHashSet<T, S>where
S: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, S> Send for LinkedHashSet<T, S>
impl<T, S> Sync for LinkedHashSet<T, S>
impl<T, S> Unpin for LinkedHashSet<T, S>where
S: Unpin,
impl<T, S> UnsafeUnpin for LinkedHashSet<T, S>where
S: UnsafeUnpin,
impl<T, S> UnwindSafe for LinkedHashSet<T, S>where
S: UnwindSafe,
T: RefUnwindSafe,
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<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.