Struct sized_chunks::sparse_chunk::SparseChunk [−][src]
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
impl<A, N> SparseChunk<A, N> where
N: Bits + ChunkLength<A>,
[src]
N: Bits + ChunkLength<A>,
pub const CAPACITY: usize
[src]
The maximum number of elements a SparseChunk
can contain.
pub fn new() -> Self
[src]
Construct a new empty chunk.
pub fn unit(index: usize, value: A) -> Self
[src]
Construct a new chunk with one item.
pub fn pair(index1: usize, value1: A, index2: usize, value2: A) -> Self
[src]
Construct a new chunk with two items.
pub fn len(&self) -> usize
[src]
Get the length of the chunk.
pub fn is_empty(&self) -> bool
[src]
Test if the chunk is empty.
pub fn is_full(&self) -> bool
[src]
Test if the chunk is at capacity.
pub fn insert(&mut self, index: usize, value: A) -> Option<A>
[src]
Insert a new value at a given index.
Returns the previous value at that index, if any.
pub fn remove(&mut self, index: usize) -> Option<A>
[src]
Remove the value at a given index.
Returns the value, or None
if the index had no value.
pub fn pop(&mut self) -> Option<A>
[src]
Remove the first value present in the array.
Returns the value that was removed, or None
if the array was empty.
pub fn get(&self, index: usize) -> Option<&A>
[src]
Get the value at a given index.
pub fn get_mut(&mut self, index: usize) -> Option<&mut A>
[src]
Get a mutable reference to the value at a given index.
pub unsafe fn get_unchecked(&self, index: usize) -> &A
[src]
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.
pub unsafe fn get_unchecked_mut(&mut self, index: usize) -> &mut A
[src]
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.
pub fn indices(&self) -> BitmapIter<'_, N>
[src]
Make an iterator over the indices which contain values.
pub fn first_index(&self) -> Option<usize>
[src]
Find the first index which contains a value.
pub fn iter(&self) -> Iter<'_, A, N>ⓘ
[src]
Make an iterator of references to the values contained in the array.
pub fn iter_mut(&mut self) -> IterMut<'_, A, N>ⓘ
[src]
Make an iterator of mutable references to the values contained in the array.
pub fn drain(self) -> Drain<A, N>ⓘ
[src]
Turn the chunk into an iterator over the values contained within it.
pub fn entries(&self) -> impl Iterator<Item = (usize, &A)>
[src]
Make an iterator of pairs of indices and references to the values contained in the array.
pub fn option_iter(&self) -> OptionIter<'_, A, N>ⓘNotable traits for OptionIter<'a, A, N>
impl<'a, A, N: Bits + ChunkLength<A>> Iterator for OptionIter<'a, A, N> type Item = Option<&'a A>;
[src]
Notable traits for OptionIter<'a, A, N>
impl<'a, A, N: Bits + ChunkLength<A>> Iterator for OptionIter<'a, A, N> 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.
pub fn option_iter_mut(&mut self) -> OptionIterMut<'_, A, N>ⓘNotable traits for OptionIterMut<'a, A, N>
impl<'a, A, N: Bits + ChunkLength<A>> Iterator for OptionIterMut<'a, A, N> type Item = Option<&'a mut A>;
[src]
Notable traits for OptionIterMut<'a, A, N>
impl<'a, A, N: Bits + ChunkLength<A>> Iterator for OptionIterMut<'a, A, N> 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.
pub fn option_drain(self) -> OptionDrain<A, N>ⓘNotable traits for OptionDrain<A, N>
impl<'a, A, N: Bits + ChunkLength<A>> Iterator for OptionDrain<A, N> type Item = Option<A>;
[src]
Notable traits for OptionDrain<A, N>
impl<'a, A, N: Bits + ChunkLength<A>> Iterator for OptionDrain<A, N> 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
impl<'a, A, N> Arbitrary<'a> for SparseChunk<A, N> where
A: Clone,
Option<A>: Arbitrary<'a>,
N: ChunkLength<A> + Bits + 'static,
[src]
A: Clone,
Option<A>: Arbitrary<'a>,
N: ChunkLength<A> + Bits + 'static,
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
[src]
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self>
[src]
fn size_hint(depth: usize) -> (usize, Option<usize>)
[src]
impl<A: Clone, N: Bits + ChunkLength<A>> Clone for SparseChunk<A, N>
[src]
fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<A, N> Debug for SparseChunk<A, N> where
A: Debug,
N: Bits + ChunkLength<A>,
[src]
A: Debug,
N: Bits + ChunkLength<A>,
impl<A, N: Bits + ChunkLength<A>> Default for SparseChunk<A, N>
[src]
impl<A, N: Bits + ChunkLength<A>> Drop for SparseChunk<A, N>
[src]
impl<A, N> Eq for SparseChunk<A, N> where
A: Eq,
N: Bits + ChunkLength<A>,
[src]
A: Eq,
N: Bits + ChunkLength<A>,
impl<A, N: Bits + ChunkLength<A>> FromIterator<Option<A>> for SparseChunk<A, N>
[src]
fn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = Option<A>>,
[src]
I: IntoIterator<Item = Option<A>>,
impl<A, N: Bits + ChunkLength<A>> Index<usize> for SparseChunk<A, N>
[src]
type Output = A
The returned type after indexing.
fn index(&self, index: usize) -> &Self::Output
[src]
impl<A, N: Bits + ChunkLength<A>> IndexMut<usize> for SparseChunk<A, N>
[src]
impl<A, N: Bits + ChunkLength<A>> IntoIterator for SparseChunk<A, N>
[src]
type Item = A
The type of the elements being iterated over.
type IntoIter = Drain<A, N>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<A, N> PartialEq<BTreeMap<usize, A>> for SparseChunk<A, N> where
A: PartialEq,
N: Bits + ChunkLength<A>,
[src]
A: PartialEq,
N: Bits + ChunkLength<A>,
fn eq(&self, other: &BTreeMap<usize, A>) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<A, N> PartialEq<HashMap<usize, A, RandomState>> for SparseChunk<A, N> where
A: PartialEq,
N: Bits + ChunkLength<A>,
[src]
A: PartialEq,
N: Bits + ChunkLength<A>,
fn eq(&self, other: &HashMap<usize, A>) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<A, N> PartialEq<SparseChunk<A, N>> for SparseChunk<A, N> where
A: PartialEq,
N: Bits + ChunkLength<A>,
[src]
A: PartialEq,
N: Bits + ChunkLength<A>,
impl<A, N> PoolClone for SparseChunk<A, N> where
A: Clone,
N: Bits + ChunkLength<A>,
[src]
A: Clone,
N: Bits + ChunkLength<A>,
unsafe fn clone_uninit(&self, target: &mut MaybeUninit<Self>)
[src]
impl<A, N> PoolDefault for SparseChunk<A, N> where
N: Bits + ChunkLength<A>,
[src]
N: Bits + ChunkLength<A>,
unsafe fn default_uninit(target: &mut MaybeUninit<Self>)
[src]
Auto Trait Implementations
impl<A, N> RefUnwindSafe for SparseChunk<A, N> where
<N as ChunkLength<A>>::SizedType: RefUnwindSafe,
<N as Bits>::Store: RefUnwindSafe,
<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,
<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,
<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,
<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,
<N as ChunkLength<A>>::SizedType: UnwindSafe,
<N as Bits>::Store: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
[src]
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,