Struct GroupMap

Source
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  I2

The 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>
where S: Default,

Source

pub fn new() -> Self

Creates a new empty map.

Source§

impl<GK, GV, IK, IV, S> GroupMap<GK, GV, IK, IV, S>
where GK: Hash + Eq + Clone, IK: Hash + Eq + Clone, S: BuildHasher,

Source

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.

Source

pub fn contains_group2<Q>(&self, key: &Q) -> bool
where GK: Borrow<Q>, Q: Hash + Eq + ?Sized,

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.

Source

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.

Source

pub fn get_group2<Q>(&self, key: &Q) -> Option<(&GV, &Vec<usize>)>
where GK: Borrow<Q>, Q: Hash + Eq + ?Sized,

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.

Source

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.

Source

pub fn get_group_mut2<Q>(&mut self, key: &Q) -> Option<(&mut GV, &Vec<usize>)>
where GK: Borrow<Q>, Q: Hash + Eq + ?Sized,

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.

Source

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.

Source

pub fn get_group_index<Q>(&self, key: &Q) -> Option<usize>
where GK: Borrow<Q>, Q: Hash + Eq + ?Sized,

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.

Source

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.

Source

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.

Source

pub fn contains_item2<Q>(&self, key: &Q) -> bool
where IK: Borrow<Q>, Q: Hash + Eq + ?Sized,

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.

Source

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.

Source

pub fn get_item2<Q>(&self, key: &Q) -> Option<&(IV, HashSet<usize, S>)>
where IK: Borrow<Q>, Q: Hash + Eq + ?Sized,

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.

Source

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.

Source

pub fn get_item_mut2<Q>( &mut self, key: &Q, ) -> Option<(&mut IV, &HashSet<usize, S>)>
where IK: Borrow<Q>, Q: Hash + Eq + ?Sized,

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.

Source

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.

Source

pub fn get_item_index<Q>(&self, key: &Q) -> Option<usize>
where IK: Borrow<Q>, Q: Hash + Eq + ?Sized,

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

pub fn iter_item(&self) -> impl Iterator<Item = (&IK, usize, &IV)>

Returns an iterator visiting all items.

The iterator yields pairs of item key, item index, and shared reference to item value.

Source§

impl<GK, GV, IK, IV, S> GroupMap<GK, GV, IK, IV, S>
where GK: Hash + Eq + Clone, IK: Hash + Eq + Clone, S: BuildHasher + Default,

Source

pub fn next_index<Q>(&self, key: &Q) -> usize
where GK: Borrow<Q>, Q: Hash + Eq + ?Sized,

Returns the next index that will be returned on the next call to either GroupMap::add_group or GroupMap::add_group_from_desc.

Source

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.

Source

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.

Source

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.

Source

pub fn remove_group2<Q>(&mut self, key: &Q) -> Option<(GK, GV)>
where GK: Borrow<Q>, Q: Hash + Eq + ?Sized,

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>

Source§

fn clone(&self) -> GroupMap<GK, GV, IK, IV, S>

Returns a duplicate 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<GK: Debug, GV: Debug, IK: Debug, IV: Debug, S: Debug> Debug for GroupMap<GK, GV, IK, IV, S>

Source§

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

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

impl<GK, GV, IK, IV, S> Default for GroupMap<GK, GV, IK, IV, S>
where S: Default,

Source§

fn default() -> Self

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

impl<GK, GV, IK, IV, S> Resource for GroupMap<GK, GV, IK, IV, S>
where GK: Send + 'static, GV: Send + 'static, IK: Send + 'static, IV: Send + 'static, S: Send + 'static,

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>
where S: Send, GK: Send, IK: Send, GV: Send, IV: Send,

§

impl<GK, GV, IK, IV, S> Sync for GroupMap<GK, GV, IK, IV, S>
where S: Sync, GK: Sync, IK: Sync, GV: Sync, IV: Sync,

§

impl<GK, GV, IK, IV, S> Unpin for GroupMap<GK, GV, IK, IV, S>
where S: Unpin, GK: Unpin, IK: Unpin, GV: Unpin, IV: Unpin,

§

impl<GK, GV, IK, IV, S> UnwindSafe for GroupMap<GK, GV, IK, IV, S>
where GK: UnwindSafe, S: UnwindSafe, IK: UnwindSafe, GV: UnwindSafe, IV: UnwindSafe,

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.