MCPcopy Index your code
hub / github.com/angular/angular / _arrayIndexOfSorted

Function _arrayIndexOfSorted

packages/core/src/util/array_utils.ts:278–294  ·  view source on GitHub ↗

* INTERNAL: Get an index of an `value` in a sorted `array` by grouping search by `shift`. * * NOTE: * - This uses binary search algorithm for fast removals. * * @param array A sorted array to binary search. * @param value The value to look for. * @param shift grouping shift. * - `0` means

(array: string[], value: string, shift: number)

Source from the content-addressed store, hash-verified

276 * inserted)
277 */
278function _arrayIndexOfSorted(array: string[], value: string, shift: number): number {
279 ngDevMode && assertEqual(Array.isArray(array), true, 'Expecting an array');
280 let start = 0;
281 let end = array.length >> shift;
282 while (end !== start) {
283 const middle = start + ((end - start) >> 1); // find the middle.
284 const current = array[middle << shift];
285 if (value === current) {
286 return middle << shift;
287 } else if (current > value) {
288 end = middle;
289 } else {
290 start = middle + 1; // We already searched middle so make it non-inclusive by adding 1
291 }
292 }
293 return ~(end << shift);
294}

Callers 2

arrayIndexOfSortedFunction · 0.85
keyValueArrayIndexOfFunction · 0.85

Calls 2

assertEqualFunction · 0.90
isArrayMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…