Struct sized_chunks::sparse_chunk::SparseChunk
source · [−]pub struct SparseChunk<A, N: Bits + ChunkLength<A> = U64> { /* private fields */ }Expand description
A fixed capacity sparse array.
An inline sparse array of up to N items of type A, where N is an
Unsigned type level numeral. You can think of it as an array
of Option<A>, where the discriminant (whether the value is Some<A> or
None) is kept in a bitmap instead of adjacent to the value.
Because the bitmap is kept in a primitive type, the maximum value of N is
currently 128, corresponding to a type of u128. The type of the bitmap
will be the minimum unsigned integer type required to fit the number of bits
required. Thus, disregarding memory alignment rules, the allocated size of a
SparseChunk will be uX + A * N where uX is the type of the
discriminant bitmap, either u8, u16, u32, u64 or u128.
Examples
// Construct a chunk with a 20 item capacity
let mut chunk = SparseChunk::<i32, U20>::new();
// Set the 18th index to the value 5.
chunk.insert(18, 5);
// Set the 5th index to the value 23.
chunk.insert(5, 23);
assert_eq!(chunk.len(), 2);
assert_eq!(chunk.get(5), Some(&23));
assert_eq!(chunk.get(6), None);
assert_eq!(chunk.get(18), Some(&5));Implementations
sourceimpl<A, N: Bits + ChunkLength<A>> SparseChunk<A, N>
impl<A, N: Bits + ChunkLength<A>> SparseChunk<A, N>
sourcepub fn pair(index1: usize, value1: A, index2: usize, value2: A) -> Self
pub fn pair(index1: usize, value1: A, index2: usize, value2: A) -> Self
Construct a new chunk with two items.
sourcepub fn insert(&mut self, index: usize, value: A) -> Option<A>
pub fn insert(&mut self, index: usize, value: A) -> Option<A>
Insert a new value at a given index.
Returns the previous value at that index, if any.
sourcepub fn remove(&mut self, index: usize) -> Option<A>
pub fn remove(&mut self, index: usize) -> Option<A>
Remove the value at a given index.
Returns the value, or None if the index had no value.
sourcepub fn pop(&mut self) -> Option<A>
pub fn pop(&mut self) -> Option<A>
Remove the first value present in the array.
Returns the value that was removed, or None if the array was empty.
sourcepub fn get_mut(&mut self, index: usize) -> Option<&mut A>
pub fn get_mut(&mut self, index: usize) -> Option<&mut A>
Get a mutable reference to the value at a given index.
sourcepub fn indices(&self) -> BitmapIter<N>ⓘNotable traits for Iter<Size>impl<Size: Bits> Iterator for Iter<Size> type Item = usize;
pub fn indices(&self) -> BitmapIter<N>ⓘNotable traits for Iter<Size>impl<Size: Bits> Iterator for Iter<Size> type Item = usize;
Make an iterator over the indices which contain values.
sourcepub fn first_index(&self) -> Option<usize>
pub fn first_index(&self) -> Option<usize>
Find the first index which contains a value.
sourcepub fn iter(&self) -> Iter<'_, A, N>ⓘNotable traits for Iter<'a, A, N>impl<'a, A, N: Bits + ChunkLength<A>> Iterator for Iter<'a, A, N> type Item = &'a A;
pub fn iter(&self) -> Iter<'_, A, N>ⓘNotable traits for Iter<'a, A, N>impl<'a, A, N: Bits + ChunkLength<A>> Iterator for Iter<'a, A, N> type Item = &'a A;
Make an iterator of references to the values contained in the array.
sourcepub fn iter_mut(&mut self) -> IterMut<'_, A, N>ⓘNotable traits for IterMut<'a, A, N>impl<'a, A, N: Bits + ChunkLength<A>> Iterator for IterMut<'a, A, N> type Item = &'a mut A;
pub fn iter_mut(&mut self) -> IterMut<'_, A, N>ⓘNotable traits for IterMut<'a, A, N>impl<'a, A, N: Bits + ChunkLength<A>> Iterator for IterMut<'a, A, N> type Item = &'a mut A;
Make an iterator of mutable references to the values contained in the array.
Trait Implementations
sourceimpl<A: Clone, N: Bits + ChunkLength<A>> Clone for SparseChunk<A, N>
impl<A: Clone, N: Bits + ChunkLength<A>> Clone for SparseChunk<A, N>
sourceimpl<A, N> Debug for SparseChunk<A, N> where
A: Debug,
N: Bits + ChunkLength<A>,
impl<A, N> Debug for SparseChunk<A, N> where
A: Debug,
N: Bits + ChunkLength<A>,
sourceimpl<A, N: Bits + ChunkLength<A>> Drop for SparseChunk<A, N>
impl<A, N: Bits + ChunkLength<A>> Drop for SparseChunk<A, N>
sourceimpl<A, N: Bits + ChunkLength<A>> Index<usize> for SparseChunk<A, N>
impl<A, N: Bits + ChunkLength<A>> Index<usize> for SparseChunk<A, N>
sourceimpl<A, N: Bits + ChunkLength<A>> IndexMut<usize> for SparseChunk<A, N>
impl<A, N: Bits + ChunkLength<A>> IndexMut<usize> for SparseChunk<A, N>
sourceimpl<A, N: Bits + ChunkLength<A>> IntoIterator for SparseChunk<A, N>
impl<A, N: Bits + ChunkLength<A>> IntoIterator for SparseChunk<A, N>
sourceimpl<A, N> PartialEq<BTreeMap<usize, A>> for SparseChunk<A, N> where
A: PartialEq,
N: Bits + ChunkLength<A>,
impl<A, N> PartialEq<BTreeMap<usize, A>> for SparseChunk<A, N> where
A: PartialEq,
N: Bits + ChunkLength<A>,
sourceimpl<A, N> PartialEq<HashMap<usize, A, RandomState>> for SparseChunk<A, N> where
A: PartialEq,
N: Bits + ChunkLength<A>,
impl<A, N> PartialEq<HashMap<usize, A, RandomState>> for SparseChunk<A, N> where
A: PartialEq,
N: Bits + ChunkLength<A>,
sourceimpl<A, N> PartialEq<SparseChunk<A, N>> for SparseChunk<A, N> where
A: PartialEq,
N: Bits + ChunkLength<A>,
impl<A, N> PartialEq<SparseChunk<A, N>> for SparseChunk<A, N> where
A: PartialEq,
N: Bits + ChunkLength<A>,
impl<A, N> Eq for SparseChunk<A, N> where
A: Eq,
N: Bits + ChunkLength<A>,
Auto Trait Implementations
impl<A, N> RefUnwindSafe for SparseChunk<A, N> where
<N as ChunkLength<A>>::SizedType: RefUnwindSafe,
<N as Bits>::Store: RefUnwindSafe,
impl<A, N> Send for SparseChunk<A, N> where
<N as ChunkLength<A>>::SizedType: Send,
<N as Bits>::Store: Send,
impl<A, N> Sync for SparseChunk<A, N> where
<N as ChunkLength<A>>::SizedType: Sync,
<N as Bits>::Store: Sync,
impl<A, N> Unpin for SparseChunk<A, N> where
<N as ChunkLength<A>>::SizedType: Unpin,
<N as Bits>::Store: Unpin,
impl<A, N> UnwindSafe for SparseChunk<A, N> where
<N as ChunkLength<A>>::SizedType: UnwindSafe,
<N as Bits>::Store: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more