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

Function resize

packages/effect/src/internal/stm/tMap.ts:442–469  ·  view source on GitHub ↗
(journal: Journal.Journal, buckets: TArray.TArray<Chunk.Chunk<readonly [K, V]>>)

Source from the content-addressed store, hash-verified

440 <K, V>(self: TMap.TMap<K, V>, key: K, value: V) => STM.STM<void>
441>(3, <K, V>(self: TMap.TMap<K, V>, key: K, value: V) => {
442 const resize = (journal: Journal.Journal, buckets: TArray.TArray<Chunk.Chunk<readonly [K, V]>>): void => {
443 const capacity = buckets.chunk.length
444 const newCapacity = capacity << 1
445 const newBuckets = Array.from({ length: newCapacity }, () => Chunk.empty<readonly [K, V]>())
446 let index = 0
447 while (index < capacity) {
448 const pairs = tRef.unsafeGet(buckets.chunk[index], journal)
449 const iterator = pairs[Symbol.iterator]()
450 let next: IteratorResult<readonly [K, V], any>
451 while ((next = iterator.next()) && !next.done) {
452 const newIndex = indexOf(next.value[0], newCapacity)
453 newBuckets[newIndex] = Chunk.prepend(newBuckets[newIndex], next.value)
454 }
455 index = index + 1
456 }
457 // insert new pair
458 const newIndex = indexOf(key, newCapacity)
459 newBuckets[newIndex] = Chunk.prepend(newBuckets[newIndex], [key, value] as const)
460
461 const newArray: Array<TRef.TRef<Chunk.Chunk<readonly [K, V]>>> = []
462 index = 0
463 while (index < newCapacity) {
464 newArray[index] = new tRef.TRefImpl(newBuckets[index])
465 index = index + 1
466 }
467 const newTArray: TArray.TArray<Chunk.Chunk<readonly [K, V]>> = new tArray.TArrayImpl(newArray)
468 tRef.unsafeSet(self.tBuckets, newTArray, journal)
469 }
470 return core.effect<never, void>((journal) => {
471 const buckets = tRef.unsafeGet(self.tBuckets, journal)
472 const capacity = buckets.chunk.length

Callers 1

tMap.tsFile · 0.85

Calls 3

unsafeGetMethod · 0.80
indexOfFunction · 0.70
nextMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…