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>
impl<T> IndexedHashSet<T>
Sourcepub fn get_ref_by_hash<'a, Q>(&'a self, elem: &Q) -> Option<&'a T>
pub fn get_ref_by_hash<'a, Q>(&'a self, elem: &Q) -> Option<&'a T>
Get a reference to the stored element by hash.
Sourcepub fn get_index_by_hash<'a, Q>(&'a self, elem: &Q) -> Option<RcIndex>
pub fn get_index_by_hash<'a, Q>(&'a self, elem: &Q) -> Option<RcIndex>
Get the index of the stored element by hash.
Sourcepub fn get_ref_by_index<'a>(&'a self, idx: &RcIndex) -> Option<&'a T>
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
.
Sourcepub fn insert(&mut self, elem: T) -> Option<RcIndex>
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()
!
Sourcepub fn get_or_insert(&mut self, elem: &T) -> RcIndexwhere
T: Clone,
pub fn get_or_insert(&mut self, elem: &T) -> RcIndexwhere
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.
Sourcepub fn drop_unused(&mut self) -> usize
pub fn drop_unused(&mut self) -> usize
Drop all entries whose usage_cnt
is zero.
Trait Implementations§
Source§impl<T> Debug for IndexedHashSet<T>where
T: 'static + Debug,
impl<T> Debug for IndexedHashSet<T>where
T: 'static + Debug,
Source§impl<T: 'static> Default for IndexedHashSet<T>
impl<T: 'static> Default for IndexedHashSet<T>
Source§impl<'a, T> Index<&'a RcIndex> for IndexedHashSet<T>
Allows to access the set like set[&rc_idx]
.
impl<'a, T> Index<&'a RcIndex> for IndexedHashSet<T>
Allows to access the set like set[&rc_idx]
.
This panics if the RcIndex
used is not from this IndexedHashSet
.
impl<T> Send for IndexedHashSet<T>
The !Send
internal references are only used internally. Therefore, this
type is safe to be Send
.