pub enum TargetRep {
None,
Sparse(Vec<(u16, ChildArc)>),
Default(Vec<Option<ChildArc>>),
}Expand description
T-4: per-node representation of the resident-child-pointer array.
Faithful to JE INTargetRep (INTargetRep.java), the abstract array of
target pointers to an IN’s cached children. These arrays are usually
sparse — most upper INs have NO resident children — so JE never stores a
full per-slot Node[] until many children are actually cached:
None—INTargetRep.None: a shared singleton, 0 child-pointer bytes, used when no children are cached (the common case for upper INs).getreturns null for every slot.Sparse—INTargetRep.Sparse: a small parallel(index, target)[]for 1..=MAX_ENTRIEScached children (JE caps at 4).get(j)is a linear scan of the index array.Default—INTargetRep.Default: the fullVec<Option<Arc>>, one slot per entry, used once more thanMAX_ENTRIESchildren are resident.
A node starts None and grows None → Sparse → Default. JE does not
shrink back when entries are nulled (it only compacts on IN-stripping) to
avoid transitionary rep churn; we follow the same policy — set_child only
inflates, and compact() (called on eviction/stripping) collapses an
empty/small Default/Sparse back toward None.
Variants§
None
INTargetRep.None — no children cached (shared-singleton semantics).
Sparse(Vec<(u16, ChildArc)>)
INTargetRep.Sparse — a few cached children, (slot_index, child).
Invariant: len() <= SPARSE_MAX_ENTRIES.
Default(Vec<Option<ChildArc>>)
INTargetRep.Default — full parallel array, one slot per entry.
Implementations§
Source§impl TargetRep
impl TargetRep
Sourcepub const SPARSE_MAX_ENTRIES: usize = 4
pub const SPARSE_MAX_ENTRIES: usize = 4
INTargetRep.Sparse.MAX_ENTRIES (INTargetRep.java) — the maximum
number of cached children the Sparse rep holds before inflating to
Default.
Sourcepub fn get(&self, idx: usize) -> Option<&ChildArc>
pub fn get(&self, idx: usize) -> Option<&ChildArc>
INTargetRep.get(idx) — the cached child for slot idx, or None.
Sourcepub fn set(&mut self, idx: usize, node: Option<ChildArc>)
pub fn set(&mut self, idx: usize, node: Option<ChildArc>)
INTargetRep.set(idx, node, parent) — set (or clear, when node is
None) the cached child for slot idx, mutating the representation
upward (None → Sparse → Default) as needed.
Sourcepub fn take(&mut self, idx: usize) -> Option<ChildArc>
pub fn take(&mut self, idx: usize) -> Option<ChildArc>
INTargetRep.None-aware take: remove and return the cached child for
slot idx, leaving the slot empty (JE IN.setTarget(idx, null) plus
returning the old target).
Sourcepub fn insert_shift(&mut self, idx: usize)
pub fn insert_shift(&mut self, idx: usize)
JE INArrayRep.copy(from, to, n, parent) adapted to slice ops: shift
the child mapping when an entry is INSERTED at idx (all children at
slots >= idx move up by one). Mirrors how Vec::insert shifts the
parallel entries array.
Sourcepub fn remove_shift(&mut self, idx: usize)
pub fn remove_shift(&mut self, idx: usize)
JE INArrayRep.copy adapted: shift the child mapping when the entry at
idx is REMOVED (all children at slots > idx move down by one; the
child at idx itself is dropped). Mirrors Vec::remove.
Sourcepub fn compact(&mut self)
pub fn compact(&mut self)
INTargetRep.compact(parent) — collapse toward the most compact rep:
an empty rep becomes None; a Default with <= MAX_ENTRIES children
becomes Sparse (or None). Called when an IN is stripped/evicted.
Sourcepub fn resident_count(&self) -> usize
pub fn resident_count(&self) -> usize
Number of resident (non-null) children.
Sourcepub fn iter_children(&self) -> Box<dyn Iterator<Item = ChildArc> + '_>
pub fn iter_children(&self) -> Box<dyn Iterator<Item = ChildArc> + '_>
Iterate every resident child (in unspecified order).
Sourcepub fn memory_size(&self) -> usize
pub fn memory_size(&self) -> usize
INTargetRep.calculateMemorySize() — heap bytes of the rep itself
(excluding the children it points at). None is 0 (shared singleton),
matching INTargetRep.None.calculateMemorySize() == 0.