MCPcopy Index your code
hub / github.com/mitmproxy/mitmproxy / findInsertPos

Function findInsertPos

web/src/js/ducks/flows/_utils.ts:98–121  ·  view source on GitHub ↗
(
    list: T[],
    item: T,
    sort: Comparer<T>,
)

Source from the content-addressed store, hash-verified

96
97/// Find the insertion position in a sorted array.
98export function findInsertPos<T>(
99 list: T[],
100 item: T,
101 sort: Comparer<T>,
102): number {
103 let low = 0,
104 high = list.length;
105
106 // fast path: insert at end
107 if (high === 0 || sort(list[high - 1], item) <= 0) {
108 return high;
109 }
110
111 while (low < high) {
112 const middle = (low + high) >>> 1;
113 if (sort(item, list[middle]) >= 0) {
114 low = middle + 1;
115 } else {
116 high = middle;
117 }
118 }
119
120 return low;
121}

Callers 2

_utilsSpec.tsFile · 0.90
insertViewItemFunction · 0.85

Calls 1

sortFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…