Struct ckb_util::LinkedHashSet

source ·
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>>

source

pub fn new() -> LinkedHashSet<T, BuildHasherDefault<DefaultHasher>>

Creates a linked hash set.

§Examples
use ckb_util::LinkedHashSet;
let set: LinkedHashSet<i32> = LinkedHashSet::new();
source

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>
where T: Eq + Hash, S: BuildHasher,

source

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);
source

pub fn capacity(&self) -> usize

Returns the number of elements the set can hold without reallocating.

source

pub fn len(&self) -> usize

Returns the number of elements in the set.

source

pub fn is_empty(&self) -> bool

Returns true if the set contains no elements.

source

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.

source

pub fn iter(&self) -> Iter<'_, T>

Gets an iterator visiting all elements in insertion order.

The iterator element type is &'a T.

source

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.

source

pub fn clear(&mut self)

Clears the set of all value.

Trait Implementations§

source§

impl<T: Hash + Eq> Default for LinkedHashSet<T, BuildHasherDefault<DefaultHasher>>

source§

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>
where T: Eq + Hash, S: BuildHasher,

source§

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)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

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>
where T: Eq + Hash, S: BuildHasher,

§

type Item = &'a T

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, T>

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

fn into_iter(self) -> Iter<'a, T>

Creates an iterator from a value. Read more
source§

impl<T, S> IntoIterator for LinkedHashSet<T, S>
where T: Eq + Hash, S: BuildHasher,

§

type Item = T

The type of the elements being iterated over.
§

type IntoIter = IntoIter<T>

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

fn into_iter(self) -> IntoIter<T>

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<T, S> RefUnwindSafe for LinkedHashSet<T, S>

§

impl<T, S> Send for LinkedHashSet<T, S>
where S: Send, T: Send,

§

impl<T, S> Sync for LinkedHashSet<T, S>
where S: Sync, T: Sync,

§

impl<T, S> Unpin for LinkedHashSet<T, S>
where S: Unpin,

§

impl<T, S> UnwindSafe for LinkedHashSet<T, S>

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

§

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

§

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.