class Antlr4::Runtime::BitSet
Constants
- MAX_BITS
Attributes
bits[R]
Public Class Methods
new()
click to toggle source
# File lib/antlr4/runtime/bit_set.rb, line 8 def initialize @bits = 0 end
Public Instance Methods
cardinality()
click to toggle source
# File lib/antlr4/runtime/bit_set.rb, line 31 def cardinality RumourHash.bit_count(@bits) end
clear(idx = nil)
click to toggle source
# File lib/antlr4/runtime/bit_set.rb, line 16 def clear(idx = nil) # check for zero to avoid trying to take the log2 of it, which # returns -Infinity if !idx || bits == 0 @bits = 0 return end @bits &= 2**Math.log2(bits).ceil - 2**idx - 1 end
get(x)
click to toggle source
# File lib/antlr4/runtime/bit_set.rb, line 27 def get(x) (@bits & (1 << x)) > 0 ? true : false end
next_set_bit(bit)
click to toggle source
# File lib/antlr4/runtime/bit_set.rb, line 39 def next_set_bit(bit) result = bit i = 0 mask = (1 << bit) while i < MAX_BITS if (@bits & mask) > 0 return result end result += 1 mask <<= 1 i += 1 end -1 end
or(bit_set)
click to toggle source
# File lib/antlr4/runtime/bit_set.rb, line 35 def or(bit_set) @bits |= bit_set.bits end
set(x)
click to toggle source
# File lib/antlr4/runtime/bit_set.rb, line 12 def set(x) @bits |= (1 << x) end
to_s()
click to toggle source
# File lib/antlr4/runtime/bit_set.rb, line 54 def to_s buf = '[' buf << @bits.to_s(2) buf << ']' buf end