Skip to content

Commit

Permalink
cabinet/tyrant tables now accepting binary data as keys (put/get)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmettraux committed Jun 1, 2009
1 parent ee9627e commit 0135b85
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/rufus/tokyo/cabinet/lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@ class << self

attfunc :tab_genuid, :tctdbgenuid, [ :pointer ], :int64

attfunc :tab_get, :tctdbget, [ :pointer, :string, :int ], :pointer
attfunc :tab_get, :tctdbget, [ :pointer, :pointer, :int ], :pointer

attfunc :tab_iterinit, :tctdbiterinit, [ :pointer ], :int
attfunc :tab_iternext2, :tctdbiternext2, [ :pointer ], :string

attfunc :tab_put, :tctdbput, [ :pointer, :string, :int, :pointer ], :int
attfunc :tab_put, :tctdbput, [ :pointer, :pointer, :int, :pointer ], :int

#attfunc :tctdbput3, [ :pointer, :string, :string ], :int
# not using it anymore, Ruby can turn an array into a hash so easily
Expand Down
9 changes: 6 additions & 3 deletions lib/rufus/tokyo/cabinet/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def []= (pk, h_or_a)

m = Rufus::Tokyo::Map[h_or_a]

r = lib.tab_put(@db, pk, CabinetLib.strlen(pk), m.pointer)
r = lib.tab_put(@db, pk, Rufus::Tokyo.blen(pk), m.pointer)

m.free

Expand Down Expand Up @@ -404,8 +404,11 @@ def pointer
# (the actual #[] method is provided by HashMethods)
#
def get (k)
m = lib.tab_get(@db, k, CabinetLib.strlen(k))
return nil if m.address == 0 # :( too bad, but it works

m = lib.tab_get(@db, k, Rufus::Tokyo.blen(k))

return nil if m.address == 0

Map.to_h(m) # which frees the map
end

Expand Down
4 changes: 2 additions & 2 deletions lib/rufus/tokyo/tyrant/lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ class << self

attfunc :tab_genuid, :tcrdbtblgenuid, [ :pointer ], :int64

attfunc :tab_get, :tcrdbtblget, [ :pointer, :string, :int ], :pointer
attfunc :tab_get, :tcrdbtblget, [ :pointer, :pointer, :int ], :pointer

attfunc :tab_iterinit, :tcrdbiterinit, [ :pointer ], :int
attfunc :tab_iternext2, :tcrdbiternext2, [ :pointer ], :string

attfunc :tab_put, :tcrdbtblput, [ :pointer, :string, :int, :pointer ], :int
attfunc :tab_put, :tcrdbtblput, [ :pointer, :pointer, :int, :pointer ], :int

attfunc :tab_out, :tcrdbtblout, [ :pointer, :string, :int ], :int

Expand Down
6 changes: 6 additions & 0 deletions spec/table_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@
@t['pk0'].should.equal({ 'a' => 'A' })
end

it 'should store binary data \0' do
s = "toto#{0.chr}nada"
@t[s] = { s => s }
@t[s].should.equal({ s => s })
end

end


Expand Down
6 changes: 6 additions & 0 deletions spec/tyrant_table_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@
}.should.raise(NoMethodError)
end

it 'should store binary data \0' do
s = "toto#{0.chr}nada"
@t[s] = { s => s }
@t[s].should.equal({ s => s })
end

end


Expand Down

0 comments on commit 0135b85

Please sign in to comment.