Skip to main content

TargetRep

Enum TargetRep 

Source
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:

  • NoneINTargetRep.None: a shared singleton, 0 child-pointer bytes, used when no children are cached (the common case for upper INs). get returns null for every slot.
  • SparseINTargetRep.Sparse: a small parallel (index, target)[] for 1..=MAX_ENTRIES cached children (JE caps at 4). get(j) is a linear scan of the index array.
  • DefaultINTargetRep.Default: the full Vec<Option<Arc>>, one slot per entry, used once more than MAX_ENTRIES children 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

Source

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.

Source

pub fn get(&self, idx: usize) -> Option<&ChildArc>

INTargetRep.get(idx) — the cached child for slot idx, or None.

Source

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.

Source

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).

Source

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.

Source

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.

Source

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.

Source

pub fn resident_count(&self) -> usize

Number of resident (non-null) children.

Source

pub fn is_empty(&self) -> bool

True if no children are cached (INTargetRep.None or empty).

Source

pub fn iter_children(&self) -> Box<dyn Iterator<Item = ChildArc> + '_>

Iterate every resident child (in unspecified order).

Source

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.

Trait Implementations§

Source§

impl Debug for TargetRep

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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.