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

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.

Get the capacity of a chunk of this type.

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.

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.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Executes the destructor for this type. 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 !=.

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.

Should always be Self

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.