NodeIdRegistry<TKey> class
A bidirectional registry from opaque user keys to dense integer "nids".
Callers that maintain per-nid dense arrays must:
- Grow those arrays so their length is at least length whenever
allocate returns
grew: true. - 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. - Zero their per-nid slot whenever release returns a non-null nid.
The registry does not own any per-nid arrays itself.
Constructors
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
keyis 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
assertat call sites so release builds pay nothing. -
isFree(
int nid) → bool -
Whether the slot
nidis free (either out of range, or currently in the recycle pool). O(1). -
keyOf(
int nid) → TKey? -
Reverse lookup: returns the key for
nid, ornullifnidis free or out of range. -
keyOfUnchecked(
int nid) → TKey -
Hot-path reverse lookup.
nidmust refer to a live slot within[0, length); behavior on a free slot is a nullable-cast failure in checked mode and undefined in production. Use keyOf when unsure. -
nidOf(
TKey key) → int -
Forward lookup with sentinel: returns the nid for
key, or noNid ifkeyis 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, ornullifkeywas 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, ornullifkeyis not registered. Matches the API of the underlyingMap<TKey, int>.