Class: Antlr4::Runtime::BitSet

Inherits:
Object
  • Object
show all
Defined in:
lib/antlr4/runtime/bit_set.rb

Constant Summary collapse

MAX_BITS =
128

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBitSet


12
13
14
# File 'lib/antlr4/runtime/bit_set.rb', line 12

def initialize
  @bits = 0
end

Instance Attribute Details

#bitsObject (readonly)

Returns the value of attribute bits


10
11
12
# File 'lib/antlr4/runtime/bit_set.rb', line 10

def bits
  @bits
end

Instance Method Details

#cardinalityObject


24
25
26
# File 'lib/antlr4/runtime/bit_set.rb', line 24

def cardinality
  bit_count(@bits)
end

#get(x) ⇒ Object


20
21
22
# File 'lib/antlr4/runtime/bit_set.rb', line 20

def get(x)
  (@bits & (1 << x)) > 0 ? true : false
end

#next_set_bit(bit) ⇒ Object


32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/antlr4/runtime/bit_set.rb', line 32

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) ⇒ Object


28
29
30
# File 'lib/antlr4/runtime/bit_set.rb', line 28

def or(bit_set)
  @bits |= bit_set.bits
end

#set(x) ⇒ Object


16
17
18
# File 'lib/antlr4/runtime/bit_set.rb', line 16

def set(x)
  @bits |= (1 << x)
end

#to_sObject


47
48
49
50
51
52
# File 'lib/antlr4/runtime/bit_set.rb', line 47

def to_s
  buf = '['
  buf << @bits.to_s(2)
  buf << ']'
  buf
end