pub struct SparseList<T, const N: u64> { /* private fields */ }Expand description
A list with a maximum length of N that exposes its tree structure
for sparse fill-in: materialized indices, cached subtree roots, or
implicit zero-hashes for never-written regions.
Hash is byte-identical to a fully-materialised List<T, N> with the
same effective contents.
Implementations§
Source§impl<T, const N: u64> SparseList<T, N>
impl<T, const N: u64> SparseList<T, N>
Sourcepub fn iter(&self) -> impl Iterator<Item = (u64, &MissingOr<T>)>
pub fn iter(&self) -> impl Iterator<Item = (u64, &MissingOr<T>)>
Iterator over (index, MissingOr<T>) for materialized entries only.
Sourcepub fn iter_mut(&mut self) -> impl Iterator<Item = (u64, &mut MissingOr<T>)>
pub fn iter_mut(&mut self) -> impl Iterator<Item = (u64, &mut MissingOr<T>)>
Mutable iterator over (index, &mut MissingOr<T>) for materialized
entries only. Used by callers that need to rewrite entry values
in place (e.g., resolving Ref targets to Hash after settle).
Sourcepub fn entries_count(&self) -> usize
pub fn entries_count(&self) -> usize
Number of materialized entries. Distinct from len,
which is the logical length (max index + 1).
Sourcepub fn get(&self, idx: u64) -> Option<&MissingOr<T>>
pub fn get(&self, idx: u64) -> Option<&MissingOr<T>>
Look up a single entry by leaf index. O(log n).
Sourcepub fn insert(
&mut self,
idx: u64,
value: MissingOr<T>,
) -> Result<(), DecodeError>
pub fn insert( &mut self, idx: u64, value: MissingOr<T>, ) -> Result<(), DecodeError>
Insert a materialized entry. Updates len to max(len, idx + 1).
O(n) — sorted shift on insert. If idx is already present, the
existing value is overwritten (matching BTreeMap::insert semantics).
Sourcepub fn remove(&mut self, idx: u64) -> Option<MissingOr<T>>
pub fn remove(&mut self, idx: u64) -> Option<MissingOr<T>>
Remove the entry at idx, returning its previous value if any.
Does not decrement len — the logical length is independent
of which indices are materialized.
Sourcepub fn set_len(&mut self, len: u64) -> Result<(), DecodeError>
pub fn set_len(&mut self, len: u64) -> Result<(), DecodeError>
Set the logical length explicitly (does not affect entries).
Sourcepub fn cache_subtree_root(&mut self, depth: usize, idx: u64, root: [u8; 32])
pub fn cache_subtree_root(&mut self, depth: usize, idx: u64, root: [u8; 32])
Cache a precomputed subtree root at tree position (depth, idx).
depth == 0 corresponds to the root; deeper means closer to leaves.
O(n) — sorted insert into cached_subtree_roots.
Sourcepub fn cached_subtree_roots_count(&self) -> usize
pub fn cached_subtree_roots_count(&self) -> usize
Number of cached subtree roots. Used by fmt::Debug.
Trait Implementations§
Source§impl<T: Decode, const N: u64> Decode for SparseList<T, N>
impl<T: Decode, const N: u64> Decode for SparseList<T, N>
Source§fn is_ssz_fixed_len() -> bool
fn is_ssz_fixed_len() -> bool
true iff this type is fixed-length.Source§fn ssz_fixed_len() -> usize
fn ssz_fixed_len() -> usize
BYTES_PER_LENGTH_OFFSET.Source§fn from_ssz_bytes(bytes: &[u8]) -> Result<Self, DecodeError>
fn from_ssz_bytes(bytes: &[u8]) -> Result<Self, DecodeError>
bytes, rejecting trailing input.Source§impl<T, const N: u64> Default for SparseList<T, N>
impl<T, const N: u64> Default for SparseList<T, N>
Source§impl<T: Encode, const N: u64> Encode for SparseList<T, N>
impl<T: Encode, const N: u64> Encode for SparseList<T, N>
Source§fn is_ssz_fixed_len() -> bool
fn is_ssz_fixed_len() -> bool
true iff this type is fixed-length (no variable-length fields).Source§fn ssz_fixed_len() -> usize
fn ssz_fixed_len() -> usize
BYTES_PER_LENGTH_OFFSET (i.e. the size of the offset slot).Source§fn ssz_bytes_len(&self) -> usize
fn ssz_bytes_len(&self) -> usize
self when serialized.Source§fn ssz_append(&self, buf: &mut Vec<u8>)
fn ssz_append(&self, buf: &mut Vec<u8>)
self to buf.Source§fn is_basic_type() -> bool
fn is_basic_type() -> bool
true for “basic” SSZ types (uintN, bool), which pack adjacent
elements into shared 32-byte chunks for merkleization. Composite
types (containers, lists, structs) return false (the default).