pub struct GroupMap<GK, GV, IK, IV, S> { /* private fields */ }Expand description
A hash map containing Groups and Items.
Conceptually, group contains items in it, and item can belong to multiple groups. They cannot exist without relationship to each other. In other words, they must be linked. See a diagram below. In this map, group has an ordered links to items, while item has an unordered links to groups.
Groups G0 G1
/\ /\
Items I0 I1 I2The map provides you some ways to access groups and items by their keys and indices. If possible, prefer to use index to key because it can be faster.
Implementations§
Source§impl<GK, GV, IK, IV, S> GroupMap<GK, GV, IK, IV, S>
impl<GK, GV, IK, IV, S> GroupMap<GK, GV, IK, IV, S>
Sourcepub fn contains_group(&self, index: usize) -> bool
pub fn contains_group(&self, index: usize) -> bool
Returns true if the map contains a group at the given group index.
Consider using GroupMap::contains_group2 if you need to know whether
the map contains it or not by a key.
Sourcepub fn contains_group2<Q>(&self, key: &Q) -> bool
pub fn contains_group2<Q>(&self, key: &Q) -> bool
Returns true if the map contains a group corresponding to the given group key.
Consider using GroupMap::contains_group if you need to know whether
the map contains it or not by an index.
Sourcepub fn get_group(&self, index: usize) -> Option<(&GV, &Vec<usize>)>
pub fn get_group(&self, index: usize) -> Option<(&GV, &Vec<usize>)>
Retrieves a shared reference to a group and related item indices by the given group index.
Consider using GroupMap::get_group2 if you need to get a group by
a key.
Sourcepub fn get_group2<Q>(&self, key: &Q) -> Option<(&GV, &Vec<usize>)>
pub fn get_group2<Q>(&self, key: &Q) -> Option<(&GV, &Vec<usize>)>
Retrieves a shared reference to a group and related item indices by the given group key.
Consider using GroupMap::get_group if you need to get a group by
an index.
Sourcepub fn get_group_mut(&mut self, index: usize) -> Option<(&mut GV, &Vec<usize>)>
pub fn get_group_mut(&mut self, index: usize) -> Option<(&mut GV, &Vec<usize>)>
Retrieves a mutable reference to a group and related item indices by the given group index.
Consider using GroupMap::get_group_mut2 if you need to get a group
by a key.
Sourcepub fn get_group_mut2<Q>(&mut self, key: &Q) -> Option<(&mut GV, &Vec<usize>)>
pub fn get_group_mut2<Q>(&mut self, key: &Q) -> Option<(&mut GV, &Vec<usize>)>
Retrieves a mutable reference to a group and related item indices by the given group key.
Consider using GroupMap::get_group_mut if you need to get a group
by an index.
Sourcepub fn get_group_key(&self, index: usize) -> Option<&GK>
pub fn get_group_key(&self, index: usize) -> Option<&GK>
Retrieves group key corresponding to the given group index.
You can also get a group index from a key using
GroupMap::get_group_index.
Sourcepub fn get_group_index<Q>(&self, key: &Q) -> Option<usize>
pub fn get_group_index<Q>(&self, key: &Q) -> Option<usize>
Retrieves a group index corresponding to the given group key.
You can also get a group key from an index using
GroupMap::get_group_key.
Sourcepub fn iter_group(&self) -> impl Iterator<Item = (&GK, usize, &GV)>
pub fn iter_group(&self) -> impl Iterator<Item = (&GK, usize, &GV)>
Returns an iterator visiting all groups.
The iterator yields pairs of group key, group index, and shared reference to group value.
Sourcepub fn contains_item(&self, index: usize) -> bool
pub fn contains_item(&self, index: usize) -> bool
Returns true if the map contains an item at the given item index.
Consider using GroupMap::contains_item2 if you need to know whether
the map contains it or not by a key.
Sourcepub fn contains_item2<Q>(&self, key: &Q) -> bool
pub fn contains_item2<Q>(&self, key: &Q) -> bool
Returns true if the map contains an item corresponding to the given item key.
Consider using GroupMap::contains_item if you need to know whether
the map contains it or not by an index.
Sourcepub fn get_item(&self, index: usize) -> Option<&(IV, HashSet<usize, S>)>
pub fn get_item(&self, index: usize) -> Option<&(IV, HashSet<usize, S>)>
Retrieves a shared reference to an item and related group indices by the given item index.
Consider using GroupMap::get_item2 if you need to get an item by a
key.
Sourcepub fn get_item2<Q>(&self, key: &Q) -> Option<&(IV, HashSet<usize, S>)>
pub fn get_item2<Q>(&self, key: &Q) -> Option<&(IV, HashSet<usize, S>)>
Retrieves a shared reference to an item and related group indices by the given item key.
Consider using GroupMap::get_item if you need to get an item by an
index.
Sourcepub fn get_item_mut(
&mut self,
index: usize,
) -> Option<(&mut IV, &HashSet<usize, S>)>
pub fn get_item_mut( &mut self, index: usize, ) -> Option<(&mut IV, &HashSet<usize, S>)>
Retrieves a mutable reference to an item and related group indices by the given item index.
Consider using GroupMap::get_item_mut2 if you need to get an item by
a key.
Sourcepub fn get_item_mut2<Q>(
&mut self,
key: &Q,
) -> Option<(&mut IV, &HashSet<usize, S>)>
pub fn get_item_mut2<Q>( &mut self, key: &Q, ) -> Option<(&mut IV, &HashSet<usize, S>)>
Retrieves a mutable reference to an item and related group indices by the given item key.
Consider using GroupMap::get_item_mut if you need to get an item by
an index.
Sourcepub fn get_item_key(&self, index: usize) -> Option<&IK>
pub fn get_item_key(&self, index: usize) -> Option<&IK>
Retrieves an item key corresponding to the given item index.
You can also get an item index from a key using
GroupMap::get_item_index.
Sourcepub fn get_item_index<Q>(&self, key: &Q) -> Option<usize>
pub fn get_item_index<Q>(&self, key: &Q) -> Option<usize>
Retrieves an item index corresponding to the given item key.
You can also get an item key from an index using
GroupMap::get_item_key.
Source§impl<GK, GV, IK, IV, S> GroupMap<GK, GV, IK, IV, S>
impl<GK, GV, IK, IV, S> GroupMap<GK, GV, IK, IV, S>
Sourcepub fn next_index<Q>(&self, key: &Q) -> usize
pub fn next_index<Q>(&self, key: &Q) -> usize
Returns the next index that will be returned on the next call to
either GroupMap::add_group or GroupMap::add_group_from_desc.
Sourcepub fn add_group(
&mut self,
desc: impl DescribeGroup<GK, GV, IK, IV>,
) -> Result<usize, GroupDesc<GK, GV, IK, IV>>
pub fn add_group( &mut self, desc: impl DescribeGroup<GK, GV, IK, IV>, ) -> Result<usize, GroupDesc<GK, GV, IK, IV>>
Inserts a group and related items into the map from the given group descriptor.
This method is a simple wrapper of GroupMap::add_group_from_desc for
easy use.
Sourcepub fn add_group_from_desc(
&mut self,
desc: GroupDesc<GK, GV, IK, IV>,
) -> Result<usize, GroupDesc<GK, GV, IK, IV>>
pub fn add_group_from_desc( &mut self, desc: GroupDesc<GK, GV, IK, IV>, ) -> Result<usize, GroupDesc<GK, GV, IK, IV>>
Inserts a group and related items into the map from the given group descriptor.
Note that this method doesn’t overwrite anything. Therefore, if the map already contains the same group key, returns error. With respect to item, only relation to the group is adapted and item value is dropped if the map already contains the item. If you want replace, remove old one first.
§Panics
Panics if the descriptor doesn’t contain any items in it. Group cannot
exist without relationship with items. See GroupMap documentation
for more details.
Sourcepub fn remove_group(&mut self, index: usize) -> Option<(GK, GV)>
pub fn remove_group(&mut self, index: usize) -> Option<(GK, GV)>
Removes a group at the given group index from the map.
Related items are automatically removed as well if they don’t have relationships anymore by the removal of the group.
Consider using GroupMap::remove_group2 if you need to remove a group
by a key.
Sourcepub fn remove_group2<Q>(&mut self, key: &Q) -> Option<(GK, GV)>
pub fn remove_group2<Q>(&mut self, key: &Q) -> Option<(GK, GV)>
Removes a group corresponding to the given group key from the map.
Related items are automatically removed as well if they don’t have relationships anymore by the removal of the group.
Consider using GroupMap::remove_group if you need to remove a group
by an index.
Trait Implementations§
Source§impl<GK: Clone, GV: Clone, IK: Clone, IV: Clone, S: Clone> Clone for GroupMap<GK, GV, IK, IV, S>
impl<GK: Clone, GV: Clone, IK: Clone, IV: Clone, S: Clone> Clone for GroupMap<GK, GV, IK, IV, S>
Source§impl<GK: Debug, GV: Debug, IK: Debug, IV: Debug, S: Debug> Debug for GroupMap<GK, GV, IK, IV, S>
impl<GK: Debug, GV: Debug, IK: Debug, IV: Debug, S: Debug> Debug for GroupMap<GK, GV, IK, IV, S>
impl<GK, GV, IK, IV, S> Resource for GroupMap<GK, GV, IK, IV, S>
Auto Trait Implementations§
impl<GK, GV, IK, IV, S> Freeze for GroupMap<GK, GV, IK, IV, S>where
S: Freeze,
impl<GK, GV, IK, IV, S> RefUnwindSafe for GroupMap<GK, GV, IK, IV, S>
impl<GK, GV, IK, IV, S> Send for GroupMap<GK, GV, IK, IV, S>
impl<GK, GV, IK, IV, S> Sync for GroupMap<GK, GV, IK, IV, S>
impl<GK, GV, IK, IV, S> Unpin for GroupMap<GK, GV, IK, IV, S>
impl<GK, GV, IK, IV, S> UnwindSafe for GroupMap<GK, GV, IK, IV, S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more