Class: BitDatabase
- Inherits:
-
Object
- Object
- BitDatabase
- Defined in:
- lib/chem/utils/bitdb.rb
Constant Summary collapse
- ARCH =
32
Instance Attribute Summary collapse
-
#bit_length ⇒ Object
readonly
Returns the value of attribute bit_length.
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(filename, bit_length) ⇒ BitDatabase
constructor
A new instance of BitDatabase.
- #push(ary) ⇒ Object
Constructor Details
#initialize(filename, bit_length) ⇒ BitDatabase
Returns a new instance of BitDatabase.
19 20 21 22 23 24 25 26 |
# File 'lib/chem/utils/bitdb.rb', line 19 def initialize(filename, bit_length) @out = File.open(filename + ".dat", "w") @idx = File.open(filename + ".inf", "w") @bit_length = bit_length @n_bytes = (bit_length - 1) / ARCH + 1 @idx.write [@bit_length, @n_bytes].pack("l*") @current = 0 end |
Instance Attribute Details
#bit_length ⇒ Object (readonly)
Returns the value of attribute bit_length.
17 18 19 |
# File 'lib/chem/utils/bitdb.rb', line 17 def bit_length @bit_length end |
Class Method Details
.open(filename, bit_length) {|db| ... } ⇒ Object
43 44 45 46 47 |
# File 'lib/chem/utils/bitdb.rb', line 43 def self.open(filename, bit_length) db = new(filename, bit_length) yield db db.close end |
Instance Method Details
#close ⇒ Object
37 38 39 40 41 |
# File 'lib/chem/utils/bitdb.rb', line 37 def close @idx.write [@current * 1000].pack("l*") @idx.close @out.close end |