( capacity: number, data: Chunk.Chunk<readonly [K, V]> )
| 64 | |
| 65 | /** @internal */ |
| 66 | const allocate = <K, V>( |
| 67 | capacity: number, |
| 68 | data: Chunk.Chunk<readonly [K, V]> |
| 69 | ): STM.STM<TMap.TMap<K, V>> => { |
| 70 | const buckets = Array.from({ length: capacity }, () => Chunk.empty<readonly [K, V]>()) |
| 71 | const distinct = new Map<K, V>(data) |
| 72 | let size = 0 |
| 73 | for (const entry of distinct) { |
| 74 | const index = indexOf(entry[0], capacity) |
| 75 | buckets[index] = pipe(buckets[index], Chunk.prepend(entry)) |
| 76 | size = size + 1 |
| 77 | } |
| 78 | return pipe( |
| 79 | tArray.fromIterable(buckets), |
| 80 | core.flatMap((buckets) => |
| 81 | pipe( |
| 82 | tRef.make(buckets), |
| 83 | core.flatMap((tBuckets) => |
| 84 | pipe( |
| 85 | tRef.make(size), |
| 86 | core.map((tSize) => new TMapImpl(tBuckets, tSize)) |
| 87 | ) |
| 88 | ) |
| 89 | ) |
| 90 | ) |
| 91 | ) |
| 92 | } |
| 93 | |
| 94 | /** @internal */ |
| 95 | export const empty = <K, V>(): STM.STM<TMap.TMap<K, V>> => fromIterable<K, V>([]) |
no test coverage detected