Struct datazoo::index_multimap::IndexMultimap
source · 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§
Trait Implementations§
source§impl<K: Clone + Index, V: Clone + From<usize>> Clone for IndexMultimap<K, V>
impl<K: Clone + Index, V: Clone + From<usize>> Clone for IndexMultimap<K, V>
source§fn clone(&self) -> IndexMultimap<K, V>
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)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl<K: Index, V: From<usize> + Index> FromIterator<(K, V)> for IndexMultimap<K, V>
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
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> 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
Mutably borrows from an owned value. Read more