[][src]Struct indexed_hash_set::IndexedHashSet

pub struct IndexedHashSet<T> where
    T: 'static, 
{ /* fields omitted */ }

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

Implementations

impl<T> IndexedHashSet<T> where
    T: 'static + Eq + Hash
[src]

pub fn new() -> Self[src]

A new, empty set.

pub fn len(&self) -> usize[src]

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

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

Get the usage count of an element by hash.

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

Get a reference to the stored element by hash.

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

Get the index of the stored element by hash.

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

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.

#[must_use = "If not stored usage count of the new element goes to zero."]pub fn insert(&mut self, elem: T) -> Option<RcIndex>[src]

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()!

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

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

pub fn drop_unused(&mut self) -> usize[src]

Drop all entries whose usage_cnt is zero.

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

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

Trait Implementations

impl<T: Debug> Debug for IndexedHashSet<T> where
    T: 'static, 
[src]

impl<T: 'static> Default for IndexedHashSet<T>[src]

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

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

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

type Output = T

The returned type after indexing.

impl<T> Send for IndexedHashSet<T>[src]

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

Auto Trait Implementations

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.