Sha256: fa2fb2580c29a110e7d3dfb6b1823fda2b24081eabf3bfe89f7f867031fcaf87

Contents?: true

Size: 916 Bytes

Versions: 2

Compression:

Stored size: 916 Bytes

Contents

#!/usr/bin/ruby

require 'bdb1'
module BDB1
  class Bcomp < Btree
    extend Marshal

    def bdb1_bt_compare(a, b)
      a <=> b
    end
  end
end

record1Class = Struct.new('Record1', :f1, :f2 ,:f3)
record2Class = Struct.new('Record2', :f3, :f2 ,:f1)

File.delete('tmp/hash1.bdb') if File.exists?('tmp/hash1.bdb')

hash1 = BDB1::Bcomp.create('tmp/hash1.bdb', "w", 0644,
			  'set_pagesize' => 1024) 
f1 = 'aaaa'
f2 = 'lmno'
f3 = 'rrrr'
10000.times do |i|
  rec1 = record1Class.new
  rec1.f1 = f1 = f1.succ
  rec1.f2 = f2 = f2.succ
  rec1.f3 = f3 = f3.succ
  hash1[rec1.f1] = rec1 
end

File.delete('tmp/hash2.bdb') if File.exists?('tmp/hash2.bdb')

hash2 = BDB1::Bcomp.create('tmp/hash2.bdb', "w", 0644, 
			  'set_pagesize' => 1024)
hash1.each do |k,rec1|
  rec2 = record2Class.new
  rec2.f1 = rec1.f1
  rec2.f2 = rec1.f2
  rec2.f3 = rec1.f3
  hash2[rec2.f1] = rec2
  puts "Record2 #{hash2[rec2.f1].inspect}"
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bdb1-0.2.5 examples/record.rb
bdb1-0.2.4 examples/record.rb