773
}
774
775
>
function intervalSearch(T: IntervalTree, intervalStart: number, intervalEnd: number, filterOwnerId: number, filterOutValidation: boolean, filterFontDecorations: boolean, cachedVersionId: number, onlyMarginDecorations: boolean): IntervalNode[] {
intervalTree.ts
776
>
// https://en.wikipedia.org/wiki/Interval_tree#Augmented_tree
777
>
// Now, it is known that two intervals A and B overlap only when both
778
>
// A.low <= B.high and A.high >= B.low. When searching the trees for
779
>
// nodes overlapping with a given interval, you can immediately skip:
780
>
// a) all nodes to the right of nodes whose low value is past the end of the given interval.
781
>
// b) all nodes that have their maximum 'high' value below the start of the given interval.
782
>
783
>
let node = T.root;
784
>
let delta = 0;
785
>
let nodeMaxEnd = 0;
786
>
let nodeStart = 0;
787
>
let nodeEnd = 0;
788
>
const result: IntervalNode[] = [];
789
>
let resultLen = 0;
790
>
while (node !== SENTINEL) {
791
>
if (getNodeIsVisited(node)) {
792
>
// going up from this node
793
>
setNodeIsVisited(node.left, false);
794
>
setNodeIsVisited(node.right, false);
795
>
if (node === node.parent.right) {
796
delta -= node.parent.delta;
797
}
799
>
continue;
800
>
}
801
>
802
>
if (!getNodeIsVisited(node.left)) {
803
>
// first time seeing this node
804
>
nodeMaxEnd = delta + node.maxEnd;
805
>
if (nodeMaxEnd < intervalStart) {
806
// cover case b) from above
807
// there is no need to search this node or its children