pub struct IndexMultimap<K: Index, V: From<usize>> { /* private fields */ }
Expand description

A multimap that goes from an integer to multiple integers.

This is a 1-to-N mapping, see PackedIntArray for 1-to-(1|0) mapping. JaggedBitset is an alternative in case you expect the largest row to be way larger than the smaller ones.

It is not recommended to use this data structure if you expect to have large values in your key/value space. Or a single very long row and most other rows empty or wtih very low values.

This data structure might be a good solution if you have an index to a small array or an incrementing counter.

Design

This is basically a wrapper around BitMatrix, where K is the row index and V are indices in the row bitset.

Example

use datazoo::IndexMultimap;

let multimap: IndexMultimap<usize, usize> = [
    (0, 1), (0, 5), (0, 2), (0, 2),
    (1, 7), (1, 0), (1, 1),
    (2, 32), (2, 0), (2, 12), (2, 2), (2, 11), (2, 10), (2, 13), (2, 4),
    (4, 1)
].into_iter().collect();
let rows: [&[usize]; 5] = [
    &[1, 2, 5],
    &[0, 1, 7],
    &[0, 2, 4, 10, 11, 12, 13, 32],
    &[],
    &[1],
];
for (i, row) in rows.iter().enumerate() {
    let multimap_row: Box<[usize]> = multimap.get(&i).collect();
    assert_eq!(*row, &*multimap_row, "{i}");
}

Implementations§

source§

impl<K: Index, V: From<usize>> IndexMultimap<K, V>

source

pub fn get<'a>(&'a self, key: &K) -> impl Iterator<Item = V> + 'a

Get the values associated with given K

Trait Implementations§

source§

impl<K: Clone + Index, V: Clone + From<usize>> Clone for IndexMultimap<K, V>

source§

fn clone(&self) -> IndexMultimap<K, V>

Returns a copy 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<K: Debug + Index, V: Debug + From<usize>> Debug for IndexMultimap<K, V>

source§

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

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

impl<K: Index, V: From<usize> + Index> FromIterator<(K, V)> for IndexMultimap<K, V>

source§

fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> Self

Create a IndexMultimap with all associations.

Note that K and V will be dropped.

Auto Trait Implementations§

§

impl<K, V> RefUnwindSafe for IndexMultimap<K, V>

§

impl<K, V> Send for IndexMultimap<K, V>

§

impl<K, V> Sync for IndexMultimap<K, V>

§

impl<K, V> Unpin for IndexMultimap<K, V>

§

impl<K, V> UnwindSafe for IndexMultimap<K, V>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.