NodeIdRegistry<TKey> class

A bidirectional registry from opaque user keys to dense integer "nids".

Callers that maintain per-nid dense arrays must:

  1. Grow those arrays so their length is at least length whenever allocate returns grew: true.
  2. Reset their per-nid slot to a defined default inside the allocation path (either after every allocate call, or conditionally on isNew), since recycled slots carry stale data from the previous occupant.
  3. Zero their per-nid slot whenever release returns a non-null nid.

The registry does not own any per-nid arrays itself.

Constructors

NodeIdRegistry()

Properties

freeSlotCount → int
Number of freed slots available for reuse.
no setter
hashCode → int
The hash code for this object.
no setterinherited
length → int
Number of nid slots ever allocated (including freed slots currently in the recycle pool). Per-nid dense arrays maintained by the caller must have capacity at least this value.
no setter
liveCount → int
Number of live (registered) keys.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

allocate(TKey key) → ({bool grew, bool isNew, int nid})
Allocates a nid for key. Idempotent for already-registered keys.
clear() → void
Resets the registry to its initial empty state. Callers must separately clear any per-nid arrays they maintain.
contains(TKey key) → bool
Whether key is currently registered.
debugAssertConsistent() → void
Debug-only: verifies the forward and reverse maps agree and that every freed nid has a null reverse entry. Throws StateError on any inconsistency. Wrapped in assert at call sites so release builds pay nothing.
isFree(int nid) → bool
Whether the slot nid is free (either out of range, or currently in the recycle pool). O(1).
keyOf(int nid) → TKey?
Reverse lookup: returns the key for nid, or null if nid is free or out of range.
keyOfUnchecked(int nid) → TKey
Hot-path reverse lookup that skips the bounds and liveness checks keyOf performs. nid must refer to a live slot within [0, length); anything else is a programming error, and a free slot fails the cast whenever the key type is non-nullable. Use keyOf when unsure.
nidOf(TKey key) → int
Forward lookup with sentinel: returns the nid for key, or noNid if key is not registered. Suited to public APIs and hot paths that prefer a branch on an int over a nullable check.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
release(TKey key) → int?
Releases key's nid back to the pool and returns it, or null if key was not registered. Callers must zero their per-nid arrays at the returned nid so a future allocate that recycles the slot sees a clean state.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited
operator [](TKey key) → int?
Forward lookup: returns the nid for key, or null if key is not registered. Matches the API of the underlying Map<TKey, int>.

Constants

noNid → const int
Sentinel returned by nidOf when a key is not registered. Its value is -1, matching the "not present" sentinel the controller's other index APIs return.