Expand description
Growable arrays backed by leased fabric memory.
This module provides two array types:
-
FabricVec<T>stores elements in fixed-size slots within a single memory lease. When the lease is full,grow()acquires additional leases and chains them together. Thepush()method callsgrow()automatically. -
VarFabricVec<T>stores variable-size elements using an index+heap layout. The index region holds fixed-size(offset, len)entries that point into a heap region where the actual serialized data lives. This avoids wasting space when element sizes vary widely.
§FabricVec memory layout
Offset 0: [header] len: u64 (8 bytes) | capacity: u64 (8 bytes) | stride: u64 (8 bytes)
Offset 24: [data] element 0 (stride bytes) | element 1 | ...Each element slot is stride bytes wide, determined at construction time.
Within each slot, the first 4 bytes store the serialized element length
as a little-endian u32, followed by the postcard-serialized bytes.
Variable-size types must fit within stride - 4 serialized bytes;
exceeding it returns FabricError::CapacityExceeded.
When a FabricVec grows, additional leases are acquired and stored in
an overflow chain. Elements in overflow regions are addressed by
computing which region contains the target index.
§VarFabricVec memory layout
Offset 0: [header] len: u64 (8) | index_cap: u64 (8) | heap_size: u64 (8) | heap_used: u64 (8)
Offset 32: [index region] entry 0 (12 bytes: offset u64 + len u32) | entry 1 | ...
After index: [heap region] variable-length serialized data packed contiguously§Examples
use grafos_collections::vec::FabricVec;
use grafos_std::mem::MemBuilder;
let lease = MemBuilder::new().min_bytes(4096).acquire()?;
let mut v: FabricVec<u32> = FabricVec::new(lease, 16)?;
v.push(&10)?;
v.push(&20)?;
assert_eq!(v.get(0)?, 10);
assert_eq!(v.pop()?, Some(20));Structs§
- Fabric
Vec - A growable array stored in leased fabric memory.
- Fabric
VecIter - Iterator over elements of a
FabricVec. - VarFabric
Vec - A vector that stores variable-size elements in leased fabric memory.
- VarFabric
VecIter - Iterator over elements of a
VarFabricVec.