class Antlr4::Runtime::Interval
Constants
- INTERVAL_POOL_MAX_VALUE
Attributes
creates[RW]
hits[RW]
invalid[RW]
misses[RW]
outOfRange[RW]
a[RW]
b[RW]
Public Class Methods
new(a, b)
click to toggle source
# File lib/antlr4/runtime/interval.rb, line 9 def initialize(a, b) @a = a @b = b end
of(a, b)
click to toggle source
# File lib/antlr4/runtime/interval.rb, line 29 def self.of(a, b) return Interval.new(a, b) if a != b || a < 0 || a > INTERVAL_POOL_MAX_VALUE @@cache[a] = Interval.new(a, a) if @@cache[a].nil? @@cache[a] end
Public Instance Methods
==(o)
click to toggle source
# File lib/antlr4/runtime/interval.rb, line 42 def ==(o) return false if o.nil? || !(o.is_a? Interval) @a == o.a && @b == o.b end
adjacent(other)
click to toggle source
# File lib/antlr4/runtime/interval.rb, line 79 def adjacent(other) @a == other.b + 1 || @b == other.a - 1 end
difference_not_properly_contained(other)
click to toggle source
# File lib/antlr4/runtime/interval.rb, line 95 def difference_not_properly_contained(other) diff = null if other.starts_before_non_disjoint(this) diff = Interval.of([@a, other.b + 1].max, @b) elsif other.startsAfterNonDisjoint(this) diff = Interval.of(@a, other.a - 1) end diff end
disjoint(other)
click to toggle source
# File lib/antlr4/runtime/interval.rb, line 75 def disjoint(other) starts_before_disjoint(other) || startsAfterDisjoint(other) end
hash()
click to toggle source
# File lib/antlr4/runtime/interval.rb, line 48 def hash return @_hash unless @_hash.nil? @_hash = 23 @_hash = @_hash * 31 + @a @_hash = @_hash * 31 + @b end
intersection(other)
click to toggle source
# File lib/antlr4/runtime/interval.rb, line 91 def intersection(other) Interval.of([a, other.a].max, [b, other.b].min) end
length()
click to toggle source
# File lib/antlr4/runtime/interval.rb, line 36 def length return 0 if @b < @a @b - @a + 1 end
properlyContains(other)
click to toggle source
# File lib/antlr4/runtime/interval.rb, line 83 def properlyContains(other) other.a >= @a && other.b <= @b end
startsAfter(other)
click to toggle source
# File lib/antlr4/runtime/interval.rb, line 63 def startsAfter(other) @a > other.a end
startsAfterDisjoint(other)
click to toggle source
# File lib/antlr4/runtime/interval.rb, line 67 def startsAfterDisjoint(other) @a > other.b end
startsAfterNonDisjoint(other)
click to toggle source
# File lib/antlr4/runtime/interval.rb, line 71 def startsAfterNonDisjoint(other) @a > other.a && @a <= other.b end
starts_before_disjoint(other)
click to toggle source
# File lib/antlr4/runtime/interval.rb, line 55 def starts_before_disjoint(other) @a < other.a && @b < other.a end
starts_before_non_disjoint(other)
click to toggle source
# File lib/antlr4/runtime/interval.rb, line 59 def starts_before_non_disjoint(other) @a <= other.a && @b >= other.a end
to_s()
click to toggle source
# File lib/antlr4/runtime/interval.rb, line 108 def to_s @a.to_s + '..' + @b.to_s end
union(other)
click to toggle source
# File lib/antlr4/runtime/interval.rb, line 87 def union(other) Interval.of([a, other.a].min, [b, other.b].max) end