MCPcopy Create free account
hub / github.com/effect-app/libs / insertSorted

Function insertSorted

repos/effect/packages/effect/src/TxPriorityQueue.ts:86–103  ·  view source on GitHub ↗
(chunk: Chunk<A>, value: A, ord: Order<A>)

Source from the content-addressed store, hash-verified

84 return self
85}
86
87const insertSorted = <A>(chunk: Chunk<A>, value: A, ord: Order<A>): Chunk<A> => {
88 const arr = C.toArray(chunk) as Array<A>
89 let lo = 0
90 let hi = arr.length
91 while (lo < hi) {
92 const mid = (lo + hi) >>> 1
93 if (ord(arr[mid], value) <= 0) {
94 lo = mid + 1
95 } else {
96 hi = mid
97 }
98 }
99 const out = Array(arr.length + 1) as Array<A>
100 for (let i = 0; i < lo; i++) out[i] = arr[i]
101 out[lo] = value
102 for (let i = lo; i < arr.length; i++) out[i + 1] = arr[i]
103 return C.fromIterable(out)
104}
105
106/**

Callers 1

TxPriorityQueue.tsFile · 0.85

Calls 2

toArrayMethod · 0.80
ArrayInterface · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…