On this page

Source Code: lib/util/StackedMap.js#L52

Layered map that supports child scopes while memoizing lookups from parent scopes. Layers form a linked parent chain, so createChild is O(1) instead of copying a layer array per scope. A layer's Map is only allocated on its first own write, and lookup results are memoized into the nearest Map-bearing layer of the walk — read-only layers (most block scopes) stay allocation-free and share their parent's memoized entries.

new StackedMap(): StackedMap<K, V>
Returns:StackedMap<K, V>
Source Code: lib/util/StackedMap.js#L59
Type:Map<K, InternalCell<V>>
Source Code: lib/util/StackedMap.js#L61
Type:StackedMap<K, V>
Source Code: lib/util/StackedMap.js#L268
Type:number

Returns the number of visible keys after collapsing the stack.

stackedMap.asArray(): K[]
Source Code: lib/util/StackedMap.js#L230
Returns:K[]

Returns the visible keys as an array after collapsing the stack.

stackedMap.asMap(): Map<K, Cell<V>>
Source Code: lib/util/StackedMap.js#L260
Returns:Map<K, Cell<V>>

Returns the visible contents as a plain Map.

stackedMap.asPairArray(): [K, Cell<V>][]
Source Code: lib/util/StackedMap.js#L248
Returns:[K, Cell<V>][]

Returns visible key/value pairs using the external representation.

stackedMap.asSet(): Set<K>
Source Code: lib/util/StackedMap.js#L239
Returns:Set<K>

Returns the visible keys as a Set after collapsing the stack.

stackedMap.createChild(): StackedMap<K, V>
Source Code: lib/util/StackedMap.js#L278
Returns:StackedMap<K, V>

Creates a child StackedMap that sees the current layers as its parent scope.

stackedMap.delete(item): void
Source Code: lib/util/StackedMap.js#L84
Attributes
item:K

Deletes a key from the current view, either by removing it outright in the root layer or by recording a tombstone in child layers.

stackedMap.get(item): Cell<V>
Source Code: lib/util/StackedMap.js#L143
Attributes
item:K
Returns:Cell<V>

Returns the visible value for a key, caching parent hits and misses in the nearest Map-bearing layer so repeated lookups (from this layer or any sibling below that layer) answer with a single probe.

stackedMap.has(item): boolean
Source Code: lib/util/StackedMap.js#L98
Attributes
item:K
Returns:boolean

Checks whether a key exists in the current scope chain, caching any parent lookup result in the nearest Map-bearing layer.

stackedMap.set(item, value): void
Source Code: lib/util/StackedMap.js#L71
Attributes
item:K
value:V

Stores a value in the current layer, preserving explicit undefined values with an internal marker.