Struct sized_chunks::sparse_chunk::SparseChunk
source · [−]Expand description
A fixed capacity sparse array.
An inline sparse array of up to N
items of type A
. 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.
Examples
// Construct a chunk with a 20 item capacity
let mut chunk = SparseChunk::<i32, 20>::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, const N: usize> SparseChunk<A, N> where
BitsImpl<N>: Bits,
impl<A, const N: usize> SparseChunk<A, N> where
BitsImpl<N>: Bits,
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 unsafe fn get_unchecked(&self, index: usize) -> &A
pub unsafe fn get_unchecked(&self, index: usize) -> &A
Get an unchecked reference to the value at a given index.
Safety
Uninhabited indices contain uninitialised data, so make sure you validate the index before using this method.
sourcepub unsafe fn get_unchecked_mut(&mut self, index: usize) -> &mut A
pub unsafe fn get_unchecked_mut(&mut self, index: usize) -> &mut A
Get an unchecked mutable reference to the value at a given index.
Safety
Uninhabited indices contain uninitialised data, so make sure you validate the index before using this method.
sourcepub fn indices(&self) -> BitmapIter<'_, N>
pub fn indices(&self) -> BitmapIter<'_, N>
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, const N: usize> Iterator for Iter<'a, A, N> where
BitsImpl<N>: Bits, type Item = &'a A;
pub fn iter(&self) -> Iter<'_, A, N>ⓘNotable traits for Iter<'a, A, N>impl<'a, A, const N: usize> Iterator for Iter<'a, A, N> where
BitsImpl<N>: Bits, type Item = &'a A;
BitsImpl<N>: Bits, 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, const N: usize> Iterator for IterMut<'a, A, N> where
BitsImpl<N>: Bits, type Item = &'a mut A;
pub fn iter_mut(&mut self) -> IterMut<'_, A, N>ⓘNotable traits for IterMut<'a, A, N>impl<'a, A, const N: usize> Iterator for IterMut<'a, A, N> where
BitsImpl<N>: Bits, type Item = &'a mut A;
BitsImpl<N>: Bits, type Item = &'a mut A;
Make an iterator of mutable references to the values contained in the array.
sourcepub fn drain(self) -> Drain<A, N>ⓘNotable traits for Drain<A, N>impl<'a, A, const N: usize> Iterator for Drain<A, N> where
BitsImpl<N>: Bits, type Item = A;
pub fn drain(self) -> Drain<A, N>ⓘNotable traits for Drain<A, N>impl<'a, A, const N: usize> Iterator for Drain<A, N> where
BitsImpl<N>: Bits, type Item = A;
BitsImpl<N>: Bits, type Item = A;
Turn the chunk into an iterator over the values contained within it.
sourcepub fn entries(&self) -> impl Iterator<Item = (usize, &A)>
pub fn entries(&self) -> impl Iterator<Item = (usize, &A)>
Make an iterator of pairs of indices and references to the values contained in the array.
sourcepub fn option_iter(&self) -> OptionIter<'_, A, N>ⓘNotable traits for OptionIter<'a, A, N>impl<'a, A, const N: usize> Iterator for OptionIter<'a, A, N> where
BitsImpl<N>: Bits, type Item = Option<&'a A>;
pub fn option_iter(&self) -> OptionIter<'_, A, N>ⓘNotable traits for OptionIter<'a, A, N>impl<'a, A, const N: usize> Iterator for OptionIter<'a, A, N> where
BitsImpl<N>: Bits, type Item = Option<&'a A>;
BitsImpl<N>: Bits, type Item = Option<&'a A>;
Make an iterator of Option
s of references to the values contained in the array.
Iterates over every index in the SparseChunk
, from zero to its full capacity,
returning an Option<&A>
for each index.
sourcepub fn option_iter_mut(&mut self) -> OptionIterMut<'_, A, N>ⓘNotable traits for OptionIterMut<'a, A, N>impl<'a, A, const N: usize> Iterator for OptionIterMut<'a, A, N> where
BitsImpl<N>: Bits, type Item = Option<&'a mut A>;
pub fn option_iter_mut(&mut self) -> OptionIterMut<'_, A, N>ⓘNotable traits for OptionIterMut<'a, A, N>impl<'a, A, const N: usize> Iterator for OptionIterMut<'a, A, N> where
BitsImpl<N>: Bits, type Item = Option<&'a mut A>;
BitsImpl<N>: Bits, type Item = Option<&'a mut A>;
Make an iterator of Option
s of mutable references to the values contained in the array.
Iterates over every index in the SparseChunk
, from zero to its full capacity,
returning an Option<&mut A>
for each index.
sourcepub fn option_drain(self) -> OptionDrain<A, N>ⓘNotable traits for OptionDrain<A, N>impl<'a, A, const N: usize> Iterator for OptionDrain<A, N> where
BitsImpl<N>: Bits, type Item = Option<A>;
pub fn option_drain(self) -> OptionDrain<A, N>ⓘNotable traits for OptionDrain<A, N>impl<'a, A, const N: usize> Iterator for OptionDrain<A, N> where
BitsImpl<N>: Bits, type Item = Option<A>;
BitsImpl<N>: Bits, type Item = Option<A>;
Make a draining iterator of `Option’s of the values contained in the array.
Iterates over every index in the SparseChunk
, from zero to its full capacity,
returning an Option<A>
for each index.
Trait Implementations
sourceimpl<'a, A, const N: usize> Arbitrary<'a> for SparseChunk<A, N> where
A: Clone,
Option<A>: Arbitrary<'a>,
BitsImpl<N>: Bits,
impl<'a, A, const N: usize> Arbitrary<'a> for SparseChunk<A, N> where
A: Clone,
Option<A>: Arbitrary<'a>,
BitsImpl<N>: Bits,
sourcefn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
Generate an arbitrary value of Self
from the given unstructured data. Read more
sourcefn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self>
Generate an arbitrary value of Self
from the entirety of the given unstructured data. Read more
sourceimpl<A, const N: usize> FromIterator<Option<A>> for SparseChunk<A, N> where
BitsImpl<N>: Bits,
impl<A, const N: usize> FromIterator<Option<A>> for SparseChunk<A, N> where
BitsImpl<N>: Bits,
sourcefn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = Option<A>>,
fn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = Option<A>>,
Creates a value from an iterator. Read more
sourceimpl<A, const N: usize> IntoIterator for SparseChunk<A, N> where
BitsImpl<N>: Bits,
impl<A, const N: usize> IntoIterator for SparseChunk<A, N> where
BitsImpl<N>: Bits,
sourceimpl<A, const N: usize> PartialEq<BTreeMap<usize, A>> for SparseChunk<A, N> where
A: PartialEq,
BitsImpl<N>: Bits,
impl<A, const N: usize> PartialEq<BTreeMap<usize, A>> for SparseChunk<A, N> where
A: PartialEq,
BitsImpl<N>: Bits,
sourceimpl<A, const N: usize> PartialEq<HashMap<usize, A, RandomState>> for SparseChunk<A, N> where
A: PartialEq,
BitsImpl<N>: Bits,
impl<A, const N: usize> PartialEq<HashMap<usize, A, RandomState>> for SparseChunk<A, N> where
A: PartialEq,
BitsImpl<N>: Bits,
sourceimpl<A, const N: usize> PartialEq<SparseChunk<A, N>> for SparseChunk<A, N> where
A: PartialEq,
BitsImpl<N>: Bits,
impl<A, const N: usize> PartialEq<SparseChunk<A, N>> for SparseChunk<A, N> where
A: PartialEq,
BitsImpl<N>: Bits,
sourceimpl<A, const N: usize> PoolClone for SparseChunk<A, N> where
A: Clone,
BitsImpl<N>: Bits,
impl<A, const N: usize> PoolClone for SparseChunk<A, N> where
A: Clone,
BitsImpl<N>: Bits,
sourceunsafe fn clone_uninit(&self, target: &mut MaybeUninit<Self>)
unsafe fn clone_uninit(&self, target: &mut MaybeUninit<Self>)
Clone an instance of Self
into an uninitialised instance of Self
. Read more
sourceimpl<A, const N: usize> PoolDefault for SparseChunk<A, N> where
BitsImpl<N>: Bits,
impl<A, const N: usize> PoolDefault for SparseChunk<A, N> where
BitsImpl<N>: Bits,
sourceunsafe fn default_uninit(target: &mut MaybeUninit<Self>)
unsafe fn default_uninit(target: &mut MaybeUninit<Self>)
Initialise an instance of Self
to its default state. Read more
impl<A, const N: usize> Eq for SparseChunk<A, N> where
A: Eq,
BitsImpl<N>: Bits,
Auto Trait Implementations
impl<A, const N: usize> !RefUnwindSafe for SparseChunk<A, N>
impl<A, const N: usize> !Send for SparseChunk<A, N>
impl<A, const N: usize> !Sync for SparseChunk<A, N>
impl<A, const N: usize> !Unpin for SparseChunk<A, N>
impl<A, const N: usize> !UnwindSafe for SparseChunk<A, N>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
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.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more