Sha256: b35e49c2b6246dede508976f11e8570363de10684a990d6c608b23a751e955f1
Contents?: true
Size: 714 Bytes
Versions: 1
Compression:
Stored size: 714 Bytes
Contents
module BinarySearch # Builds an index file using as source data +data_source+, which can be a # subclass of BinarySearch::DataSource or an object with a next method. def self.index(data_source, db, db_idx=nil) db_idx = db + '.idx' if db_idx.nil? records = 0 File.open(db, 'w') do |fdb| File.open(db_idx, 'w') do |fidx| last = nil while record = data_source.next if !last.nil? && last >= record raise "data is not ordered! #{last} >= #{record}" end fidx.write([fdb.pos].pack('L')) fdb.write(record) last = record records += 1 end end end records end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
binarysearch-0.0.2 | lib/binarysearch/indexer.rb |