sbdb 0.0.12.1 → 0.0.12.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.12.1
1
+ 0.0.12.2
@@ -1,5 +1,4 @@
1
1
  require 'bdb'
2
- require 'sbdb/weakhash'
3
2
  require 'sbdb/db'
4
3
  require 'sbdb/transaction'
5
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sbdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12.1
4
+ version: 0.0.12.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-08-25 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bdb
16
- requirement: &70125760218960 !ruby/object:Gem::Requirement
16
+ requirement: &70118391183960 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.2.6.5
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70125760218960
24
+ version_requirements: *70118391183960
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: ref
27
- requirement: &70125760218300 !ruby/object:Gem::Requirement
27
+ requirement: &70118391183280 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70125760218300
35
+ version_requirements: *70118391183280
36
36
  description: Simple Ruby Berkeley DB wrapper library for bdb.
37
37
  email: Denis.Knauf@gmail.com
38
38
  executables: []
@@ -49,7 +49,6 @@ files:
49
49
  - lib/sbdb/db.rb
50
50
  - lib/sbdb/environment.rb
51
51
  - lib/sbdb/transaction.rb
52
- - lib/sbdb/weakhash.rb
53
52
  - LICENSE
54
53
  homepage: http://github.com/ruby-bdb/sbdb
55
54
  licenses: []
@@ -1,59 +0,0 @@
1
- module SBDB
2
- # See http://eigenclass.org/hiki/deferred-finalizers-in-Ruby
3
- # Not threadsafe.
4
- class WeakHash
5
- attr_reader :cache
6
- def initialize cache = ::Hash.new
7
- @cache = cache
8
- @key_map = {}
9
- @rev_cache = ::Hash.new { |h,k| h[k] = {} }
10
- @reclaim_value = lambda do |value_id|
11
- if @rev_cache.has_key? value_id
12
- @rev_cache[value_id].each_key{ |key| @cache.delete key }
13
- @rev_cache.delete value_id
14
- end
15
- end
16
- @reclaim_key = lambda do |key_id|
17
- @cache.delete @key_map.delete(key_id) if @key_map.has_key? key_id
18
- end
19
- end
20
-
21
- def []=(key, value)
22
- case key
23
- when Fixnum, Symbol, true, false
24
- key2 = key
25
- else
26
- key2 = key.dup
27
- end
28
- @rev_cache[value.object_id][key2] = true
29
- @cache[key2] = value.object_id
30
- @key_map[key.object_id] = key2
31
-
32
- ObjectSpace.define_finalizer(value, @reclaim_value)
33
- ObjectSpace.define_finalizer(key, @reclaim_key)
34
- value
35
- end
36
-
37
- def [](key)
38
- value_id = @cache[key]
39
- return ObjectSpace._id2ref(value_id) unless value_id.nil?
40
- nil
41
- rescue RangeError
42
- nil
43
- end
44
-
45
- def each(&e)
46
- @cache.each do |k, vid|
47
- unless vid.nil?
48
- obj =
49
- begin
50
- ObjectSpace._id2ref vid
51
- rescue RangeError
52
- next
53
- end
54
- yield k, obj
55
- end
56
- end
57
- end
58
- end
59
- end