MCPcopy Index your code
hub / github.com/antlr/antlr4 / addInterval

Method addInterval

runtime/JavaScript/src/antlr4/misc/IntervalSet.js:31–59  ·  view source on GitHub ↗
(toAdd)

Source from the content-addressed store, hash-verified

29 }
30
31 addInterval(toAdd) {
32 if (this.intervals === null) {
33 this.intervals = [];
34 this.intervals.push(toAdd.clone());
35 } else {
36 // find insert pos
37 for (let pos = 0; pos < this.intervals.length; pos++) {
38 const existing = this.intervals[pos];
39 // distinct range -> insert
40 if (toAdd.stop < existing.start) {
41 this.intervals.splice(pos, 0, toAdd);
42 return;
43 }
44 // contiguous range -> adjust
45 else if (toAdd.stop === existing.start) {
46 this.intervals[pos] = new Interval(toAdd.start, existing.stop)
47 return;
48 }
49 // overlapping range -> adjust and reduce
50 else if (toAdd.start <= existing.stop) {
51 this.intervals[pos] = new Interval(Math.min(existing.start, toAdd.start), Math.max(existing.stop, toAdd.stop));
52 this.reduce(pos);
53 return;
54 }
55 }
56 // greater than any existing
57 this.intervals.push(toAdd.clone());
58 }
59 }
60
61 addSet(other) {
62 if (other.intervals !== null) {

Callers 4

addOneMethod · 0.95
addRangeMethod · 0.95
addSetMethod · 0.95
complementMethod · 0.95

Calls 3

reduceMethod · 0.95
pushMethod · 0.80
cloneMethod · 0.45

Tested by

no test coverage detected