Skip to main content

Module tiny_vec

Module tiny_vec 

Source
Expand description

A bounded small-vector with a u8-sized header and an optional inline buffer. Backs both the List variant of crate::AutoMap and, with INLINE = 0, TaskStorage’s lazy-fields collection.

This is functionally a SmallVec<[T; INLINE]> that is bounded at MAX elements, but with a much smaller header:

  • SmallVec stores a usize length and, in its spilled representation, a heap pointer plus a usize capacity. Three usizes of header.
  • Because the element count never exceeds MAX (<= 254), both the length and the capacity fit in a u8. TinyVec stores len: NonZeroU8 and cap: u8 — two bytes of header — and overlaps the inline array with the heap pointer in a union.

The length is stored as NonZeroU8 (holding actual_len + 1) so that 0 is a forbidden bit pattern. That niche lets the enclosing AutoMap enum fold its List/Map discriminant in for free — no separate tag word. For example AutoMap<TaskId, (), _, 3> (a NonZero-keyed set) shrinks from 32 bytes with SmallVec to 24, and AutoMap<TaskId, (), _, 0> to 16.

§Type parameters

  • INLINE — elements stored inline in the struct before spilling to the heap. INLINE = 0 (the default) is a pure heap vector with a 2-byte header — 16 B on 64-bit, vs 24 B for Vec.
  • MAX — hard cap on the element count. Defaults to MAX_LIST_SIZE. Pushing past MAX panics; growth doubles until it would exceed MAX, then caps at exactly MAX.

§Representation

  • cap == INLINE: elements live inline in data.inline[..len].
  • cap > INLINE: elements live on the heap at data.heap[..len], in an allocation of cap elements. Only reachable once more than INLINE elements are inserted; capped at MAX.

Structs§

Drain
Draining iterator returned by TinyVec::drain.
IntoIter
By-value iterator returned by TinyVec::into_iter.
TinyVec
Bounded small-vector with an optional inline buffer; see the module docs.