Class: Chem::BitMatrix
- Inherits:
-
Object
- Object
- Chem::BitMatrix
- Defined in:
- lib/chem/utils/ullmann.rb
Instance Attribute Summary collapse
-
#has_matrix ⇒ Object
Returns the value of attribute has_matrix.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#n_bytes ⇒ Object
readonly
Returns the value of attribute n_bytes.
-
#widht ⇒ Object
readonly
Returns the value of attribute widht.
Instance Method Summary collapse
- #bit_str ⇒ Object
-
#initialize(height, width) ⇒ BitMatrix
constructor
A new instance of BitMatrix.
- #set(row, col) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(height, width) ⇒ BitMatrix
Returns a new instance of BitMatrix.
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/chem/utils/ullmann.rb', line 93 def initialize(height, width) @height = height @width = width @n_bytes = (width - 1) / ARCH + 1 @bits = [] height.times do |n| @bits[n] = [] @n_bytes.times do |m| @bits[n][m] = 0 end end @has_matrix = true end |
Instance Attribute Details
#has_matrix ⇒ Object
Returns the value of attribute has_matrix.
91 92 93 |
# File 'lib/chem/utils/ullmann.rb', line 91 def has_matrix @has_matrix end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
90 91 92 |
# File 'lib/chem/utils/ullmann.rb', line 90 def height @height end |
#n_bytes ⇒ Object (readonly)
Returns the value of attribute n_bytes.
90 91 92 |
# File 'lib/chem/utils/ullmann.rb', line 90 def n_bytes @n_bytes end |
#widht ⇒ Object (readonly)
Returns the value of attribute widht.
90 91 92 |
# File 'lib/chem/utils/ullmann.rb', line 90 def widht @widht end |
Instance Method Details
#bit_str ⇒ Object
125 126 127 |
# File 'lib/chem/utils/ullmann.rb', line 125 def bit_str @bits.flatten.pack("L*") end |
#set(row, col) ⇒ Object
107 108 109 |
# File 'lib/chem/utils/ullmann.rb', line 107 def set(row, col) @bits[row][col / ARCH] += (1 << (col % ARCH)) end |
#to_s ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/chem/utils/ullmann.rb', line 111 def to_s s = " " @width.times{|n| s << "%d" % (n % 10)} s << "\n" @bits.each_with_index do |ary, idx| s << "%3d " % idx ary.each_with_index do |a, idx2| s << bit_to_str(a, (idx2 == @n_bytes - 1) ? (@width % ARCH) : ARCH) end s << "\n" end s end |