pub struct SparseChunk<A, const N: usize> where
    BitsImpl<N>: Bits
{ /* private fields */ }
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

The maximum number of elements a SparseChunk can contain.

Construct a new empty chunk.

Construct a new chunk with one item.

Construct a new chunk with two items.

Get the length of the chunk.

Test if the chunk is empty.

Test if the chunk is at capacity.

Insert a new value at a given index.

Returns the previous value at that index, if any.

Remove the value at a given index.

Returns the value, or None if the index had no value.

Remove the first value present in the array.

Returns the value that was removed, or None if the array was empty.

Get the value at a given index.

Get a mutable reference to the value at a given index.

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.

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.

Make an iterator over the indices which contain values.

Find the first index which contains a value.

Make an iterator of references to the values contained in the array.

Make an iterator of mutable references to the values contained in the array.

Turn the chunk into an iterator over the values contained within it.

Make an iterator of pairs of indices and references to the values contained in the array.

Make an iterator of Options 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.

Make an iterator of Options 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.

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

Generate an arbitrary value of Self from the given unstructured data. Read more

Generate an arbitrary value of Self from the entirety of the given unstructured data. Read more

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Executes the destructor for this type. Read more

Creates a value from an iterator. Read more

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

Performs the mutable indexing (container[index]) operation. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Clone an instance of Self into an uninitialised instance of Self. Read more

Initialise an instance of Self to its default state. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.