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

Function allocate

packages/effect/src/internal/stm/tMap.ts:66–92  ·  view source on GitHub ↗
(
  capacity: number,
  data: Chunk.Chunk<readonly [K, V]>
)

Source from the content-addressed store, hash-verified

64
65/** @internal */
66const 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 */
95export const empty = <K, V>(): STM.STM<TMap.TMap<K, V>> => fromIterable<K, V>([])

Callers 1

fromIterableFunction · 0.70

Calls 4

indexOfFunction · 0.70
makeMethod · 0.65
mapMethod · 0.65
pipeFunction · 0.50

Tested by

no test coverage detected