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

Method remove

packages/effect/src/internal/hashMap.ts:376–411  ·  view source on GitHub ↗
(
    edit: number,
    _shift: number,
    hash: number,
    key: K,
    removed: { value: boolean }
  )

Source from the content-addressed store, hash-verified

374 }
375
376 remove(
377 edit: number,
378 _shift: number,
379 hash: number,
380 key: K,
381 removed: { value: boolean }
382 ): Node<K, V> | undefined {
383 if (this.hash !== hash) {
384 return this
385 }
386
387 const idx = this.entries.findIndex(([k]) => Equal_.equals(k, key))
388 if (idx === -1) {
389 return this
390 }
391
392 removed.value = true
393
394 if (this.entries.length === 1) {
395 return undefined
396 }
397
398 if (this.entries.length === 2) {
399 const remaining = this.entries[idx === 0 ? 1 : 0]
400 return new LeafNode(edit, this.hash, remaining[0], remaining[1])
401 }
402
403 if (this.canEdit(edit)) {
404 this.entries.splice(idx, 1)
405 return this
406 }
407
408 const newEntries = [...this.entries]
409 newEntries.splice(idx, 1)
410 return new CollisionNode(edit, this.hash, newEntries)
411 }
412
413 iterator(): Iterator<[K, V]> {
414 return this.entries[Symbol.iterator]()

Callers

nothing calls this directly

Calls 2

equalsMethod · 0.80
canEditMethod · 0.80

Tested by

no test coverage detected