Class: Agama::Adapters::TC
- Inherits:
-
Object
- Object
- Agama::Adapters::TC
- Defined in:
- lib/agama/adapters/tokyocabinet.rb
Instance Method Summary collapse
- #close ⇒ Object
- #e_cursor ⇒ Object
- #e_del(key) ⇒ Object
- #e_get(key) ⇒ Object
- #e_put(key, value) ⇒ Object
-
#initialize(params = {}) ⇒ TC
constructor
A new instance of TC.
- #m_del(key) ⇒ Object
- #m_get(key) ⇒ Object
- #m_put(key, value) ⇒ Object
- #n_del(key) ⇒ Object
- #n_get(key) ⇒ Object
- #n_put(key, value) ⇒ Object
- #open(path) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ TC
Returns a new instance of TC.
8 9 10 11 12 13 14 15 |
# File 'lib/agama/adapters/tokyocabinet.rb', line 8 def initialize(params = {}) @e_lmemb = params[:lmemb] || 128 @e_nmemb = params[:nmemb] || 256 @e_bnum = params[:bnum] || 32749 @e_apow = params[:apow] || 8 @e_fpow = params[:fpow] || 10 @e_opts = params[:opts] || 0 end |
Instance Method Details
#close ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/agama/adapters/tokyocabinet.rb', line 43 def close if !@meta.close ecode = @meta.ecode raise "Error closing meta_db: #{@meta.errmsg(ecode)}" end if !@nodes.close ecode = @nodes.ecode raise "Error closing nodes_db: #{@nodes.errmsg(ecode)}" end if !@edges.close ecode = @edges.ecode raise "Error closing edges_db: #{@edges.errmsg(ecode)}" end end |
#e_cursor ⇒ Object
127 128 129 |
# File 'lib/agama/adapters/tokyocabinet.rb', line 127 def e_cursor return TCCursor.new(@edges, "edge") end |
#e_del(key) ⇒ Object
118 119 120 121 122 123 124 125 |
# File 'lib/agama/adapters/tokyocabinet.rb', line 118 def e_del (key) unless @edges.out(key, value) ecode = @edges.ecode raise "Error deleting from edges_db: #{@edges.errmsg(ecode)}" end true end |
#e_get(key) ⇒ Object
114 115 116 |
# File 'lib/agama/adapters/tokyocabinet.rb', line 114 def e_get (key) return @edges.get(key) end |
#e_put(key, value) ⇒ Object
105 106 107 108 109 110 111 112 |
# File 'lib/agama/adapters/tokyocabinet.rb', line 105 def e_put (key, value) unless @edges.put(key, value) ecode = @edges.ecode raise "Error inserting into edges_db: #{@edges.errmsg(ecode)}" end true end |
#m_del(key) ⇒ Object
72 73 74 75 76 77 |
# File 'lib/agama/adapters/tokyocabinet.rb', line 72 def m_del (key) unless @meta.out(key) ecode = @meta.ecode raise "Error deleting from meta_db: #{@meta.errmsg(ecode)}" end end |
#m_get(key) ⇒ Object
68 69 70 |
# File 'lib/agama/adapters/tokyocabinet.rb', line 68 def m_get (key) return @meta.get(key) end |
#m_put(key, value) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/agama/adapters/tokyocabinet.rb', line 61 def m_put (key, value) unless @meta.put(key, value) ecode = @meta.ecode raise "Error inserting meta_db: #{@meta.errmsg(ecode)}" end end |
#n_del(key) ⇒ Object
95 96 97 98 99 100 101 102 |
# File 'lib/agama/adapters/tokyocabinet.rb', line 95 def n_del (key) unless @nodes.out(key) ecode = @nodes.ecode raise "Error deleting from nodes_db: #{@nodes.errmsg(ecode)}" end true end |
#n_get(key) ⇒ Object
91 92 93 |
# File 'lib/agama/adapters/tokyocabinet.rb', line 91 def n_get (key) return @nodes.get(key) end |
#n_put(key, value) ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/agama/adapters/tokyocabinet.rb', line 82 def n_put (key, value) unless @nodes.put(key, value) ecode = @nodes.ecode raise "Error inserting into nodes_db: #{@nodes.errmsg(ecode)}" end true end |
#open(path) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/agama/adapters/tokyocabinet.rb', line 17 def open (path) @meta = HDB::new # open the meta database if !@meta.open(path + "/meta.tch", HDB::OWRITER | HDB::OCREAT) ecode = @meta.ecode raise "Error opening meta_db: #{@meta.errmsg(ecode)}" end @nodes = HDB::new # open the nodes database if !@nodes.open(path + "/nodes.tch", HDB::OWRITER | HDB::OCREAT) ecode = @nodes.ecode raise "Error opening nodes_db: #{@nodes.errmsg(ecode)}" end @edges = BDB::new @edges.tune(@e_lmemb, @e_nmemb, @e_bnum, @e_apow, @e_fpow, @e_opts) # open the edges database if !@edges.open(path + "/edges.tcb", BDB::OWRITER | BDB::OCREAT) ecode = @edges.ecode raise "Error opening edges_db: #{@edges.errmsg(ecode)}" end end |