Struct IndexedHashSet

Source
pub struct IndexedHashSet<T>
where T: 'static,
{ /* private fields */ }
Expand description

An indexed hash set. Can be accessed either by index of hashing.

Implementations§

Source§

impl<T> IndexedHashSet<T>
where T: 'static + Eq + Hash,

Source

pub fn new() -> Self

A new, empty set.

Source

pub fn len(&self) -> usize

Number of elements in the set, including the unused ones.

Source

pub fn get_cnt<Q>(&self, elem: &Q) -> Option<usize>
where T: Borrow<Q>, Q: ?Sized + Hash + Eq,

Get the usage count of an element by hash.

Source

pub fn get_ref_by_hash<'a, Q>(&'a self, elem: &Q) -> Option<&'a T>
where T: Borrow<Q>, Q: ?Sized + Hash + Eq,

Get a reference to the stored element by hash.

Source

pub fn get_index_by_hash<'a, Q>(&'a self, elem: &Q) -> Option<RcIndex>
where T: Borrow<Q>, Q: ?Sized + Hash + Eq,

Get the index of the stored element by hash.

Source

pub fn get_ref_by_index<'a>(&'a self, idx: &RcIndex) -> Option<&'a T>

Get a reference to the stored element by index.

As the index can be from another IndexedHashSet this operation is fallible.

Alternatively, the [index notation](struct.IndexedHashSet.html#impl-Index<%26’a RcIndex>) can be used, e.g. set[&rc_idx]. However, this may panic with a foreign RcIndex.

Source

pub fn insert(&mut self, elem: T) -> Option<RcIndex>

Insert a new element into the set.

If the element is already in the set None is returned else the index of the new entry is returned.

Note: The returned RcIndex is the initial usage of the entry. If it is dropped without cloning the usage_cnt goes to zero and the new element is dropped on the next drop_unused()!

Source

pub fn get_or_insert(&mut self, elem: &T) -> RcIndex
where T: Clone,

Gets the index of the element in the set if present. If not the element is inserted and the new index is returned.

Source

pub fn drop_unused(&mut self) -> usize

Drop all entries whose usage_cnt is zero.

Source

pub fn iter(&self) -> impl Iterator<Item = &T>

Iterates over all elements in the set with usage_cnt != 0.

Trait Implementations§

Source§

impl<T> Debug for IndexedHashSet<T>
where T: 'static + Debug,

Source§

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

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

impl<T: 'static> Default for IndexedHashSet<T>

Source§

fn default() -> Self

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

impl<'a, T> Index<&'a RcIndex> for IndexedHashSet<T>
where T: 'static + Eq + Hash,

Allows to access the set like set[&rc_idx].

This panics if the RcIndex used is not from this IndexedHashSet.

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: &'a RcIndex) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T> Send for IndexedHashSet<T>

The !Send internal references are only used internally. Therefore, this type is safe to be Send.

Auto Trait Implementations§

§

impl<T> Freeze for IndexedHashSet<T>

§

impl<T> !RefUnwindSafe for IndexedHashSet<T>

§

impl<T> !Sync for IndexedHashSet<T>

§

impl<T> Unpin for IndexedHashSet<T>

§

impl<T> !UnwindSafe for IndexedHashSet<T>

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

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.