MCPcopy Create free account
hub / github.com/CoderLine/alphaTab / binaryNodeSearchInner

Function binaryNodeSearchInner

packages/lsp/src/server/utils.ts:5–32  ·  view source on GitHub ↗
(
    items: T[],
    offset: number,
    left: number = 0,
    right: number = items.length,
    trailingEnd: number
)

Source from the content-addressed store, hash-verified

3import type { ClientCapabilities } from 'vscode-languageserver';
4
5function binaryNodeSearchInner<T extends alphaTab.importer.alphaTex.AlphaTexAstNode>(
6 items: T[],
7 offset: number,
8 left: number = 0,
9 right: number = items.length,
10 trailingEnd: number
11) {
12 if (left > right) {
13 return undefined;
14 }
15
16 const center = Math.trunc((left + right) / 2);
17 const centerItem = items[center];
18
19 // match
20 const end = center === items.length - 1 ? trailingEnd : items[center + 1].start!.offset;
21 if (centerItem.start!.offset <= offset && offset <= end) {
22 return centerItem;
23 }
24
25 // left half
26 if (offset < centerItem.start!.offset) {
27 return binaryNodeSearchInner(items, offset, left, center, trailingEnd);
28 }
29
30 // right half
31 return binaryNodeSearchInner(items, offset, center, right, trailingEnd);
32}
33
34export function binaryNodeSearch<T extends alphaTab.importer.alphaTex.AlphaTexAstNode>(
35 items: T[],

Callers 1

binaryNodeSearchFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected