MCPcopy
hub / github.com/anomalyco/opencode / insert

Function insert

packages/core/src/util/binary.ts:22–40  ·  view source on GitHub ↗
(array: T[], item: T, compare: (item: T) => string)

Source from the content-addressed store, hash-verified

20 }
21
22 export function insert<T>(array: T[], item: T, compare: (item: T) => string): T[] {
23 const id = compare(item)
24 let left = 0
25 let right = array.length
26
27 while (left < right) {
28 const mid = Math.floor((left + right) / 2)
29 const midId = compare(array[mid])
30
31 if (midId < id) {
32 left = mid + 1
33 } else {
34 right = mid
35 }
36 }
37
38 array.splice(left, 0, item)
39 return array
40 }
41}

Callers 1

context-epoch.tsFile · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected