Struct IdentitySet

Source
pub struct IdentitySet<T, A: Allocator = Global> { /* private fields */ }
Expand description

An ordered identity set.

This set records a list of keys wherein each key is unique.

Unlike other sets such as HashSet, this type only transforms keys as if the identity function was used.

Implementations§

Source§

impl<T> IdentitySet<T>

Source

pub const fn new() -> Self

Constructs a new, empty identity set.

Source

pub fn with_capacity(cap: usize) -> Self

Preallocates a new identity set.

§Panics

If [T; cap] could not be allocated using the global allocator, then this function will panic.

This function will also panic if cap is greater than isize::MAX.

Source

pub unsafe fn from_raw_parts(ptr: *mut T, cap: usize, len: usize) -> Self

Constructs a new identity set from raw parts.

§Safety

See IdentityMap::from_raw_parts.

Source§

impl<T, A: Allocator> IdentitySet<T, A>

Source

pub const fn new_in(alloc: A) -> Self

Constructs a new, empty identity set with a specific allocator.

Source

pub fn with_capacity_in(cap: usize, alloc: A) -> Self

Preallocates a new identity set with a specific allocator.

§Panics

If [T; cap] could not be allocated with the given allocator, then this function will panic.

This function will also panic if cap is greater than isize::MAX.

Source

pub unsafe fn from_raw_parts_in( ptr: *mut T, cap: usize, len: usize, alloc: A, ) -> Self

Constructs a new identity set from raw parts.

§Safety

See IdentityMap::from_raw_parts_in.

Source

pub fn retain<F: FnMut(&T) -> bool>(&mut self, f: F)

Retains only keys as specified by a predicate.

In other words, each key k where !f(k) is true.

§Panics

Panics if f panics.

Source

pub fn clear(&mut self)

Clears the set.

All contained keys are dropped after a call to this method. The length counter is then reset to zero.

Source

pub fn reserve(&mut self, count: usize)

Reserves additional capacity for the set.

§Panics

This method will panic if the internal buffer could not be grown. It will also panic if the new capacity of the set is greater than isize::MAX.

Source

pub fn shrink_to(&mut self, cap: usize)

Shrinks the set to a specified length.

The capacity is shrunk such that it exactly contains the current data.

§Panics

If the provided capacity is greater than the current, then this method will panic.

Source

pub fn shrink_to_fit(&mut self)

Shrinks the set to the current length.

The capacity is shrunk such that it exactly contains the current data.

Source

pub fn allocator(&self) -> &A

Borrows the set’s allocator.

Source

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

Gets an iterator of the contained keys.

Source

pub fn capacity(&self) -> usize

Retrieves the total capacity of the set.

Remember that this capacity can – if needed to – be increased using the reserve method.

Source

pub fn len(&self) -> usize

Retrieves the current length of the set.

Source

pub fn is_empty(&self) -> bool

Tests if the set is empty.

Source

pub fn as_ptr(&self) -> *const T

Gets a pointer to the set buffer.

Note that this pointer may necessarily be dangling if the set isn’t currently in an allocated state.

Source

pub fn as_mut_ptr(&mut self) -> *mut T

Gets a mutable pointer to the set buffer.

Note that this pointer may necessarily be dangling if the set isn’t currently in an allocated state.

Source

pub fn as_slice(&self) -> &[T]

Gets a slice over the set’s keys.

Source

pub fn as_mut_slice(&mut self) -> &mut [T]

Gets a mutable slice over the set’s keys.

Source§

impl<T, A> IdentitySet<T, A>
where T: Ord, A: Allocator,

Source

pub fn insert(&mut self, key: T) -> bool

Inserts a new key pair into the set.

If the provided key already exists in the set, then this method will return true. In all other cases, it will return false.

§Panics

If the set did not already hold key as a key and could not grow its buffer to accommodate the key, then this method will panic.

Source

pub fn take<U>(&mut self, key: &U) -> Option<T>
where T: Borrow<U>, U: Ord + ?Sized,

Takes a specific key out from the set.

If the provided key was not present in the set, then this method will instead return a None instance.

Source

pub fn remove(&mut self, key: &T) -> bool

Remove a specific key from the set.

This method will return true if the provided key was present in the set.

Source

pub fn get<U>(&self, key: &U) -> Option<&T>
where T: Borrow<U>, U: Ord + ?Sized,

Borrows a key.

Source

pub fn contains<U>(&self, key: &U) -> bool
where T: Borrow<U>, U: Ord + ?Sized,

Checks if the set contains the specified key.

Source

pub fn intersection<'a>(&'a self, other: &'a Self) -> Intersection<'a, T, A>

Gets an iterator denoting the intersection between two sets.

Source

pub fn difference<'a>(&'a self, other: &'a Self) -> Difference<'a, T, A>

Gets an iterator denoting the difference between two sets.

Source

pub fn symmetric_difference<'a>( &'a self, other: &'a Self, ) -> SymmetricDifference<'a, T, A>

Gets an iterator denoting the symmetric difference between two sets

Source

pub fn union<'a>(&'a self, other: &'a Self) -> Union<'a, T, A>

Gets an iterator denoting the union between two sets

Trait Implementations§

Source§

impl<T, A> BitAnd for &IdentitySet<T, A>
where T: Clone + Ord, A: Allocator + Default,

Source§

type Output = IdentitySet<T, A>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Self) -> Self::Output

Performs the & operation. Read more
Source§

impl<T, A> BitOr for &IdentitySet<T, A>
where T: Clone + Ord, A: Allocator + Default,

Source§

type Output = IdentitySet<T, A>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Self) -> Self::Output

Performs the | operation. Read more
Source§

impl<T, A> BitXor for &IdentitySet<T, A>
where T: Clone + Ord, A: Allocator + Default,

Source§

type Output = IdentitySet<T, A>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: Self) -> Self::Output

Performs the ^ operation. Read more
Source§

impl<T: Clone, A: Clone + Allocator> Clone for IdentitySet<T, A>

Source§

fn clone(&self) -> IdentitySet<T, A>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T, A> Debug for IdentitySet<T, A>
where T: Debug, A: Allocator,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, A: Allocator + Default> Default for IdentitySet<T, A>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T, A> Extend<T> for IdentitySet<T, A>
where T: Ord, A: Allocator,

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<T, A, const N: usize> From<[T; N]> for IdentitySet<T, A>
where T: Ord, A: Allocator + Default,

Source§

fn from(value: [T; N]) -> Self

Converts to this type from the input type.
Source§

impl<T, A> FromIterator<T> for IdentitySet<T, A>
where T: Ord, A: Allocator + Default,

Source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<T, A> Hash for IdentitySet<T, A>
where T: Hash, A: Allocator,

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a, T, A: Allocator> IntoIterator for &'a IdentitySet<T, A>

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, T>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T, A: Allocator> IntoIterator for IdentitySet<T, A>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T, A>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T, A> PartialEq for IdentitySet<T, A>
where T: PartialEq, A: Allocator,

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T, A> Sub for &IdentitySet<T, A>
where T: Clone + Ord, A: Allocator + Default,

Source§

type Output = IdentitySet<T, A>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl<T, A> Eq for IdentitySet<T, A>
where T: Eq, A: Allocator,

Auto Trait Implementations§

§

impl<T, A> Freeze for IdentitySet<T, A>
where A: Freeze,

§

impl<T, A> RefUnwindSafe for IdentitySet<T, A>

§

impl<T, A> Send for IdentitySet<T, A>
where A: Send, T: Send,

§

impl<T, A> Sync for IdentitySet<T, A>
where A: Sync, T: Sync,

§

impl<T, A> Unpin for IdentitySet<T, A>
where A: Unpin,

§

impl<T, A> UnwindSafe for IdentitySet<T, A>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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.