MCPcopy Create free account
hub / github.com/Effect-TS/effect / LeafNode

Class LeafNode

packages/effect/src/internal/hashMap.ts:178–280  ·  view source on GitHub ↗

@internal

Source from the content-addressed store, hash-verified

176
177/** @internal */
178class LeafNode<K, V> extends Node<K, V> {
179 readonly _tag = "LeafNode"
180
181 edit: number
182 readonly hash: number
183 key: K
184 value: V
185
186 constructor(
187 edit: number,
188 hash: number,
189 key: K,
190 value: V
191 ) {
192 super()
193 this.edit = edit
194 this.hash = hash
195 this.key = key
196 this.value = value
197 }
198
199 get size(): number {
200 return 1
201 }
202
203 get(_shift: number, hash: number, key: K): Option.Option<V> {
204 if (this.hash === hash && Equal_.equals(this.key, key)) {
205 return Option.some(this.value)
206 }
207 return Option.none()
208 }
209
210 has(_shift: number, hash: number, key: K): boolean {
211 return this.hash === hash && Equal_.equals(this.key, key)
212 }
213
214 set(
215 edit: number,
216 shift: number,
217 hash: number,
218 key: K,
219 value: V,
220 added: { value: boolean }
221 ): Node<K, V> {
222 if (this.hash === hash && Equal_.equals(this.key, key)) {
223 if (Equal_.equals(this.value, value)) {
224 return this
225 }
226 // Can mutate in-place if edit matches
227 if (this.canEdit(edit)) {
228 this.value = value
229 return this
230 }
231 return new LeafNode(edit, hash, key, value)
232 }
233
234 added.value = true
235

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected