pub struct LinkedHashSet<T, S = BuildHasherDefault<DefaultHasher>> { /* private fields */ }
Expand description
A HashSet that holds elements in insertion order.
§Examples
use ckb_util::LinkedHashSet;
let mut set = LinkedHashSet::new();
set.insert(2);
set.insert(1);
set.insert(3);
let items: Vec<i32> = set.iter().copied().collect();
assert_eq!(items, [2, 1, 3]);
Implementations§
Source§impl<T: Hash + Eq> LinkedHashSet<T, BuildHasherDefault<DefaultHasher>>
impl<T: Hash + Eq> LinkedHashSet<T, BuildHasherDefault<DefaultHasher>>
Sourcepub fn new() -> LinkedHashSet<T, BuildHasherDefault<DefaultHasher>>
pub fn new() -> LinkedHashSet<T, BuildHasherDefault<DefaultHasher>>
Creates a linked hash set.
§Examples
use ckb_util::LinkedHashSet;
let set: LinkedHashSet<i32> = LinkedHashSet::new();
Sourcepub fn with_capacity(
capacity: usize,
) -> LinkedHashSet<T, BuildHasherDefault<DefaultHasher>>
pub fn with_capacity( capacity: usize, ) -> LinkedHashSet<T, BuildHasherDefault<DefaultHasher>>
Creates an empty linked hash map with the given initial capacity.
§Examples
use ckb_util::LinkedHashSet;
let set: LinkedHashSet<i32> = LinkedHashSet::with_capacity(42);
Source§impl<T, S> LinkedHashSet<T, S>
impl<T, S> LinkedHashSet<T, S>
Sourcepub fn contains(&self, value: &T) -> bool
pub fn contains(&self, value: &T) -> bool
Returns true
if the set contains a value.
use ckb_util::LinkedHashSet;
let mut set: LinkedHashSet<_> = LinkedHashSet::new();
set.insert(1);
set.insert(2);
set.insert(3);
assert_eq!(set.contains(&1), true);
assert_eq!(set.contains(&4), false);
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of elements the set can hold without reallocating.
Sourcepub fn insert(&mut self, value: T) -> bool
pub fn insert(&mut self, value: T) -> bool
Adds a value to the set.
If the set did not have this value present, true is returned.
If the set did have this value present, false is returned.
Sourcepub fn iter(&self) -> Iter<'_, T>
pub fn iter(&self) -> Iter<'_, T>
Gets an iterator visiting all elements in insertion order.
The iterator element type is &'a T
.
Sourcepub fn difference<'a>(
&'a self,
other: &'a LinkedHashSet<T, S>,
) -> Difference<'a, T, S>
pub fn difference<'a>( &'a self, other: &'a LinkedHashSet<T, S>, ) -> Difference<'a, T, S>
Visits the values representing the difference, i.e., the values that are in self
but not in other
.
Trait Implementations§
Source§impl<T: Hash + Eq> Default for LinkedHashSet<T, BuildHasherDefault<DefaultHasher>>
impl<T: Hash + Eq> Default for LinkedHashSet<T, BuildHasherDefault<DefaultHasher>>
Source§fn default() -> LinkedHashSet<T, BuildHasherDefault<DefaultHasher>>
fn default() -> LinkedHashSet<T, BuildHasherDefault<DefaultHasher>>
Creates an empty HashSet<T>
with the Default
value for the hasher.
Source§impl<T, S> Extend<T> for LinkedHashSet<T, S>
impl<T, S> 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)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one
)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Source§impl<'a, T, S> IntoIterator for &'a LinkedHashSet<T, S>
impl<'a, T, S> IntoIterator for &'a LinkedHashSet<T, S>
Source§impl<T, S> IntoIterator for LinkedHashSet<T, S>
impl<T, S> IntoIterator 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> 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
Mutably borrows from an owned value. Read more