NodeStore<TKey, TData> class
Dense ECS-style storage for the tree's structural state.
Hands out stable integer "nids" (via the embedded NodeIdRegistry) and keeps every structural property in a typed-data array indexed by nid. Reads cost an O(1) array access; writes update the array in place.
All mutators are intentionally low-level: they update the local arrays
and propagate the _ancestorsExpandedByNid cache where relevant, but
they do not update the visible-order buffer or the
visible-subtree-size cache. The owning controller wraps these calls
when those side effects are required.
Properties
- ancestorsExpandedByNid → Uint8List
-
Read-only view of the ancestors-expanded cache.
no setter
- capacity → int
-
Capacity high-water mark (number of nid slots ever allocated, including
freed ones in the recycle pool). Per-nid arrays maintained externally
must have at least this many slots.
no setter
- depthByNid → Int32List
-
Read-only view of the depth-by-nid array.
no setter
- expandedByNid → Uint8List
-
Read-only view of the expanded-flag array.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
-
nids
→ NodeIdRegistry<
TKey> -
Bidirectional key↔nid registry with free-list recycling.
final
- onCapacityGrew → void Function(int newCapacity)?
-
Optional callback fired when
_ensureDenseCapacityreallocates the per-nid arrays. The argument is the new capacity, in slots. The controller uses this to grow its own per-nid arrays (_visibleSubtreeSizeByNid, the order buffer's reverse index) in lockstep.final - parentByNid → Int32List
-
Read-only view of the parent-nid array. Hot-path consumers (e.g. the
visible-subtree-size walker) read directly to skip per-call dispatch.
Caller must not mutate.
no setter
- rawDataLength → int
-
Internal — used by debug consistency checks.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
adopt(
TKey key) → ({bool grew, bool isNew, int nid}) -
Allocates a nid for
key(or returns the existing one) and resets every dense per-nid slot to its default. Grows the dense arrays via_ensureDenseCapacitywhen a fresh slot is appended; the onCapacityGrew callback fires from inside that path. -
ancestorsExpandedFast(
TKey key) → bool -
O(1) "are all ancestors of
keyexpanded?" check. Returns true for roots and unregistered keys. -
childListOf(
TKey key) → List< TKey> ? -
Child key list for
key, or null whenkeyhas no list allocated yet (or is unregistered). -
childListOrCreate(
TKey key) → List< TKey> -
Child key list for
key, allocating an empty list when none exists.keymust be registered. -
clear(
) → void - Releases all nids and zeros every dense array. The onCapacityGrew callback is not fired; callers that maintain external per-nid arrays are responsible for clearing them too.
-
collapseAllInRegistry(
int? maxDepth, List< TKey> roots) → void -
Clears the expanded flag for every registered node whose depth is less
than
maxDepth(or for every node whenmaxDepthis null), then rebuilds the ancestors-expanded cache fromroots. -
dataOf(
TKey key) → TreeNode< TKey, TData> ? -
Node payload for
key, or null when unregistered. -
debugAssertConsistent(
) → void -
Debug: verify per-nid data slots match the registry. Throws
StateError on inconsistency. Wrapped in
assertat call sites so release builds pay nothing. -
depthOf(
TKey key) → int -
Depth of
key, or 0 when unregistered. -
depthOfNid(
int nid) → int -
Depth of the live nid
nid. -
has(
TKey key) → bool -
Whether
keyis currently registered. -
isExpanded(
TKey key) → bool -
Whether
keyis expanded. False for unregistered keys. -
keyOf(
int nid) → TKey? -
Reverse lookup: key for
nid, or null if the slot is free. -
keyOfUnchecked(
int nid) → TKey -
Hot-path reverse lookup.
nidmust refer to a live slot. -
nidOf(
TKey key) → int? -
Nid for
key, or null when unregistered. -
nidOfOrSentinel(
TKey key) → int -
Nid for
key, or NodeIdRegistry.noNid when unregistered. Hot path. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
parentNidOf(
TKey key) → int -
Parent nid for
key, or kNoParentNid for roots / unregistered keys. Hot path — no allocation, no exception. -
parentOf(
TKey key) → TKey? -
Parent key for
key, or null for roots / unregistered keys. -
rawDataAtNid(
int nid) → TreeNode< TKey, TData> ? -
Internal — used by debug consistency checks. Returns the data slot at
nid(which may be null for freed slots). -
rebuildAllAncestorsExpanded(
List< TKey> roots) → void -
Rebuilds
_ancestorsExpandedByNidwholesale in a single pass starting fromroots. Used by bulk operations that bypass per-call propagation. -
release(
TKey key) → int? -
Releases the nid associated with
keyback to the pool and clears every dense slot. Returns the released nid, or null ifkeywasn't registered. -
setChildList(
TKey key, List< TKey> list) → void -
Replaces the child list for
key.keymust be registered. -
setData(
TKey key, TreeNode< TKey, TData> node) → void -
Sets the node payload for
key.keymust be registered. -
setDepth(
TKey key, int depth) → void -
Sets the depth of
key.keymust be registered. -
setExpanded(
TKey key, bool expanded, {bool propagate = true}) → void -
Sets the expansion flag for
key.keymust be registered. -
setParent(
TKey key, TKey? parent) → void -
Sets the parent of
keytoparent(or null for root) and refreshes the cached_ancestorsExpandedByNidbit forkey, propagating the change throughkey's subtree. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited