module RecordSearch # Builds an index file using as source data +data_source+, which can be a # subclass of RecordSearch::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