Skip to main content

Vector

Struct Vector 

Source
pub struct Vector<V> { /* private fields */ }
Expand description

A Vec-like container with per-slot dirty and validity tracking.

§Two independent bits per slot

The validity bit gives pipeline stages an Option-like read API: a downstream stage that reads via Vector::get_valid cannot reach the inner value without first matching on Some / None, so the consistency / freshness check is enforced at the type system level. See SlotWriter for the symmetric write side.

§Breaking change in 0.2.1

The legacy bypass methods get, get_updated, get_mut, iter_updated were removed in 0.2.1. All access paths now engage with the validity bit. Callers that genuinely need indexed accumulation rather than single-value-per-slot should use crate::value::buckets::Buckets instead.

Implementations§

Source§

impl<V> Vector<V>

Source

pub fn new() -> Vector<V>

Creates a new, empty Vector.

Source

pub fn with_capacity(capacity: usize) -> Vector<V>

Creates a Vector with the specified capacity.

Source

pub fn from_vec(data: Vec<V>) -> Vector<V>

Bulk constructor from an existing Vec<V>. Every slot starts valid and clean (no dirty bits set), matching the “loaded from saved state” pattern: downstream consumers can read via Vector::get_valid but won’t see a fresh round of iter_updated_* events until something is committed or invalidated.

Source

pub fn from_fill(value: V, len: usize) -> Vector<V>
where V: Clone,

Bulk constructor filled with len clones of value. Same dirty / valid semantics as Vector::from_vec: every slot starts valid + clean.

Source

pub fn with_invalid_slots(len: usize) -> Vector<V>
where V: Default,

Bulk constructor with len slots that all start invalid and clean. The backing storage is allocated — so commit(i, ..) for any i < len will not panic — but every slot reads as None via Vector::get_valid until the caller commits a value into it. Slots hold V::default() placeholders that are never exposed while invalid.

Useful for an externally-fed buffer of known size whose slots are populated incrementally: allocate once with with_invalid_slots(n), then commit real values as they arrive. Contrast with Vector::from_fill, whose slots start valid.

Source

pub fn as_slice(&self) -> &[V]

Returns the full underlying slice of values, regardless of per-slot validity or dirty state. Useful for bulk read paths where the caller has already established validity through other means (e.g. tests, snapshot serialisation).

Source

pub fn is_updated(&self) -> bool

Returns true if any element in the Vector is updated.

Source

pub fn all_updated(&self) -> bool

Returns true if every element in the Vector is updated. Returns false for an empty Vector.

Source

pub fn clear(&mut self)

Clears the Vector, removing all values.

Source

pub fn len(&self) -> usize

Returns the number of elements in the Vector.

Source

pub fn is_empty(&self) -> bool

Returns true if the Vector contains no elements.

Source

pub fn iter(&self) -> Iter<'_, V>

Returns an iterator over the elements of the Vector.

Source

pub fn iter_mut(&mut self) -> IterMut<'_, V>

Returns a mutable iterator over the elements of the Vector. Marks all elements as updated.

Source

pub fn get_mut_untracked(&mut self, index: usize) -> Option<&mut V>

Returns a mutable reference to the element at the given index without updating dirty tracking.

This is useful when callers want to reuse or clear previously touched storage between compute cycles without reporting a fresh update to downstream stages.

Source

pub fn push(&mut self, value: V)

Appends an element to the back of the Vector, marking it as updated.

The new slot is marked invalid: the pushed value is treated as a placeholder rather than a meaningful committed value. Use Vector::push_committed when the initial value is meaningful, or call Vector::commit on the new index afterwards.

Source

pub fn push_committed(&mut self, value: V)

Like Vector::push, but the new slot is marked valid.

Use this when you genuinely have a meaningful starting value for the slot; otherwise prefer push and explicitly Vector::commit later, which makes the moment the slot becomes valid explicit.

Source

pub fn pop(&mut self) -> Option<V>

Removes the last element from the Vector and returns it, or None if empty.

Source

pub fn is_valid(&self, index: usize) -> bool

Returns true if slot index is valid (has a committed value that has not been invalidated). Returns false if the index is out of bounds.

Source

pub fn is_updated_at(&self, index: usize) -> bool

Returns true if slot index was written this cycle (commit / update / invalidate / slot_writer.commit). Returns false if the index is out of bounds, or if the slot’s dirty bit was cleared by Reset::reset at end-of-cycle.

Equivalent to looking up index in the set produced by Vector::iter_updated_indices, but as an O(1) bit test rather than an iteration. Use this when you have a fixed slot index and want to decide whether to do dirty-driven work on it — avoids the per-cycle materialisation that iter_updated_indices().collect::<HashSet<_>>() would force.

Source

pub fn get_valid(&self, index: usize) -> Option<&V>

Returns a reference to slot index if (and only if) it is valid. The Option-like read accessor: mirrors Option::as_ref and forces callers to match on Some / None before reaching the inner value.

Source

pub fn commit(&mut self, index: usize, value: V)

Write value into slot index, mark the slot valid, and mark it dirty. Panics if index is out of bounds.

Source

pub fn update<F>(&mut self, index: usize, f: F)
where F: FnOnce(&mut V),

Apply f to slot index in place, then mark the slot valid and dirty.

The point of this method is to mutate a large V without moving in a fresh value the way Vector::commit does. For a wide value type, commit(i, fresh) copies the whole struct in; update(i, |v| v.field = new_field) writes only the bytes that changed.

The closure sees whatever the slot currently stores — the prior committed value, the placeholder from a non- Vector::push_committed Vector::push, or stale bytes from a slot that was Vector::invalidated. Callers that care about the prior validity should check Vector::is_valid / Vector::get_valid first.

Panics if index is out of bounds.

Source

pub fn invalidate(&mut self, index: usize)

Mark slot index invalid and dirty. The slot retains its prior data; it just becomes invisible to readers using Vector::get_valid. Panics if index is out of bounds.

Source

pub fn slot_writer(&mut self, index: usize) -> SlotWriter<'_, V>

Acquire a one-shot writer for slot index. The returned SlotWriter is #[must_use] and must be consumed via SlotWriter::commit or SlotWriter::invalidate; dropping it without consumption triggers a debug_assert! in debug builds.

Panics if index is out of bounds.

Source§

impl<V> Vector<V>

Source

pub fn iter_updated_valid(&self) -> IterUpdatedValidItems<'_, V>

Iterate dirty slots in ascending index order, yielding (index, Some(&V)) for slots that are also valid and (index, None) for dirty slots that are invalid.

Source

pub fn iter_updated_indices(&self) -> IterUpdatedIndices<'_>

Iterate indices of dirty slots in ascending order. Skips the validity check and data lookup that Vector::iter_updated_valid performs — useful when you only need the slot indices, e.g. to drive a parallel walk over another Vector or external array keyed by the same slot.

Trait Implementations§

Source§

impl<V> Default for Vector<V>

Source§

fn default() -> Vector<V>

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

impl<V> Reset for Vector<V>

Source§

type Error = Error

Clears the dirty bits and indices. Does not touch validity bits: a slot that was valid before reset stays valid after reset. Dirty is per-cycle; validity is multi-cycle.

Source§

fn reset(&mut self) -> Result<(), Error>

Clear per-cycle dirty state.
Source§

impl<V> Updated for Vector<V>

Source§

fn is_updated(&self) -> bool

Whether the value changed this cycle.

Auto Trait Implementations§

§

impl<V> Freeze for Vector<V>

§

impl<V> RefUnwindSafe for Vector<V>
where V: RefUnwindSafe,

§

impl<V> Send for Vector<V>
where V: Send,

§

impl<V> Sync for Vector<V>
where V: Sync,

§

impl<V> Unpin for Vector<V>
where V: Unpin,

§

impl<V> UnsafeUnpin for Vector<V>

§

impl<V> UnwindSafe for Vector<V>
where V: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.