rufus-tokyo 0.1.12 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.txt CHANGED
@@ -2,6 +2,15 @@
2
2
  = rufus-tokyo CHANGELOG.txt
3
3
 
4
4
 
5
+ == rufus-tokyo - 0.1.13 released 2009/06/02
6
+
7
+ - todo : putkeep implementation (by Kamal)
8
+ - todo : support for binary data (map, list, cabinet, table, tokyo/edo)
9
+ - todo : added #defrag to Rufus::Tokyo::Cabinet
10
+ - todo : added :dfunit to databases that support it
11
+ - todo : added #addint and #adddouble (#incr)
12
+
13
+
5
14
  == rufus-tokyo - 0.1.12 released 2009/04/07
6
15
 
7
16
  - todo : added ext method for calling embedded Lua function (Tyrant)
data/CREDITS.txt CHANGED
@@ -10,6 +10,7 @@ Zev Blut http://www.iknow.co.jp/users/zev
10
10
 
11
11
  == contributors
12
12
 
13
+ Kamal Fariz Mahyuddin http://github.com/kamal
13
14
  Justin Reagor http://blog.kineticweb.com/
14
15
  Benjami Yu http://github.com/byu
15
16
  mebaran http://github.com/mebaran
data/README.txt CHANGED
@@ -31,6 +31,8 @@ the rdoc is at http://rufus.rubyforge.org/rufus-tokyo/
31
31
 
32
32
  this version of rufus-tokyo works with
33
33
 
34
+ ffi 0.3.1, 0.3.5
35
+
34
36
  ruby 1.8.6
35
37
  ruby 1.9.1p0
36
38
  jruby 1.1.6
@@ -39,9 +41,12 @@ this version of rufus-tokyo works with
39
41
  TC 1.4.9 and TT 1.1.16
40
42
  TC 1.4.10 and TT 1.1.17 (adds the offset arg to query.limit)
41
43
  TC 1.4.11 and TT 1.1.18
44
+ TC 1.4.13 and TT 1.1.22 (added query.count)
45
+ TC 1.4.21 and TT 1.1.27
42
46
 
43
47
  tc-ruby 1.20 and tt-ruby 1.3 (Rufus::Edo)
44
- tc-ruby 1.21 and tt-ruby 1.4 (Rufus::Edo)
48
+ tc-ruby 1.21 and tt-ruby 1.5 (Rufus::Edo)
49
+ tc-ruby 1.21 and tt-ruby 1.7 (Rufus::Edo)
45
50
 
46
51
 
47
52
  === TC Abstract API
data/TODO.txt CHANGED
@@ -1,20 +1,24 @@
1
1
 
2
- [x] table : bench find(1) after set_index
3
- [x] table : bench insert(1) after set_index
2
+ [o] table : bench find(1) after set_index
3
+ [o] table : bench insert(1) after set_index
4
4
 
5
- [x] align edo#new on tokyo#new
5
+ [o] align edo#new on tokyo#new
6
6
  [ ] horizontal (bdb hdb fdb) tests for tokyo and edo
7
7
 
8
- [x] rdoc unix socket for tyrant
9
- [x] edo : tran
8
+ [o] rdoc unix socket for tyrant
9
+ [o] edo : tran
10
10
  [ ] bench ux socket
11
11
 
12
- [ ] TT (TC) call [lua] function
12
+ [o] TT (TC) call [lua] function
13
13
  [ ] queryout
14
14
 
15
- [ ] impl lget/lput/ldelete in Rufus::Edo::Cabinet
15
+ [o] impl lget/lput/ldelete in Rufus::Edo::Cabinet
16
16
 
17
17
  [ ] maybe supported different libs for migrations...
18
18
 
19
19
  [ ] document ENV['TOKYO_TYRANT_LIB'] & _CABINET_
20
20
 
21
+ [o] unify m/l raise trick for util map/list
22
+
23
+ [ ] misc calls (defrag) for Edo
24
+
@@ -63,22 +63,32 @@ module Rufus::Edo
63
63
  end
64
64
  end
65
65
 
66
+ # Returns the path to this database.
66
67
  #
68
+ def path
69
+
70
+ @path
71
+ end
72
+
67
73
  # No comment
68
74
  #
69
75
  def []= (k, v)
70
76
  @db.put(k, v) || raise_error
71
77
  end
72
78
 
79
+ # No comment
73
80
  #
74
- # (The actual #[] method is provided by HashMethods
81
+ def putkeep (k, v)
82
+ @db.putkeep(k, v)
83
+ end
84
+
85
+ # (The actual #[] method is provided by HashMethods)
75
86
  #
76
87
  def get (k)
77
88
  @db.get(k)
78
89
  end
79
90
  protected :get
80
91
 
81
- #
82
92
  # Removes a record from the cabinet, returns the value if successful
83
93
  # else nil.
84
94
  #
@@ -87,14 +97,12 @@ module Rufus::Edo
87
97
  @db.out(k) ? v : nil
88
98
  end
89
99
 
90
- #
91
100
  # Returns the number of records in the 'cabinet'
92
101
  #
93
102
  def size
94
103
  @db.rnum
95
104
  end
96
105
 
97
- #
98
106
  # Removes all the records in the cabinet (use with care)
99
107
  #
100
108
  # Returns self (like Ruby's Hash does).
@@ -104,14 +112,12 @@ module Rufus::Edo
104
112
  self
105
113
  end
106
114
 
107
- #
108
115
  # Returns the 'weight' of the db (in bytes)
109
116
  #
110
117
  def weight
111
118
  @db.fsiz
112
119
  end
113
120
 
114
- #
115
121
  # Closes the cabinet (and frees the datastructure allocated for it),
116
122
  # returns true in case of success.
117
123
  #
@@ -119,7 +125,6 @@ module Rufus::Edo
119
125
  @db.close || raise_error
120
126
  end
121
127
 
122
- #
123
128
  # Copies the current cabinet to a new file.
124
129
  #
125
130
  # Returns true if it was successful.
@@ -128,7 +133,6 @@ module Rufus::Edo
128
133
  @db.copy(target_path)
129
134
  end
130
135
 
131
- #
132
136
  # Copies the current cabinet to a new file.
133
137
  #
134
138
  # Does it by copying each entry afresh to the target file. Spares some
@@ -140,7 +144,6 @@ module Rufus::Edo
140
144
  @other_db.close
141
145
  end
142
146
 
143
- #
144
147
  # "synchronize updated contents of an abstract database object with
145
148
  # the file and the device"
146
149
  #
@@ -148,7 +151,6 @@ module Rufus::Edo
148
151
  @db.sync || raise_error
149
152
  end
150
153
 
151
- #
152
154
  # Returns an array of all the primary keys in the db.
153
155
  #
154
156
  # With no options given, this method will return all the keys (strings)
@@ -182,7 +184,6 @@ module Rufus::Edo
182
184
  end
183
185
  end
184
186
 
185
- #
186
187
  # Deletes all the entries whose keys begin with the given prefix
187
188
  #
188
189
  def delete_keys_with_prefix (prefix)
@@ -193,7 +194,6 @@ module Rufus::Edo
193
194
  nil
194
195
  end
195
196
 
196
- #
197
197
  # Given a list of keys, returns a Hash { key => value } of the
198
198
  # matching entries (in one sweep).
199
199
  #
@@ -217,7 +217,6 @@ module Rufus::Edo
217
217
  #++
218
218
  alias :lput :merge!
219
219
 
220
- #
221
220
  # Given a list of keys, deletes all the matching entries (in one sweep).
222
221
  #
223
222
  # Warning : this is a naive (slow) implementation.
@@ -229,15 +228,33 @@ module Rufus::Edo
229
228
  nil
230
229
  end
231
230
 
231
+ # Increments the value stored under the given key with the given increment
232
+ # (defaults to 1 (integer)).
232
233
  #
234
+ def incr (key, val=1)
235
+
236
+ v = val.is_a?(Fixnum) ? @db.addint(key, val) : @db.adddouble(key, val)
237
+
238
+ raise(EdoError.new(
239
+ "incr failed, there is probably already a string value set " +
240
+ "for the key '#{key}'"
241
+ )) unless v
242
+
243
+ v
244
+ end
245
+ alias :adddouble :incr
246
+ alias :addint :incr
247
+ alias :add_double :incr
248
+ alias :add_int :incr
249
+
233
250
  # Returns the underlying 'native' Ruby object (of the class devised by
234
251
  # Hirabayashi-san)
235
252
  #
236
253
  def original
254
+
237
255
  @db
238
256
  end
239
257
 
240
- #
241
258
  # This is rather low-level, you'd better use #transaction like in
242
259
  #
243
260
  # db.transaction do
@@ -253,7 +270,6 @@ module Rufus::Edo
253
270
  @db.tranbegin
254
271
  end
255
272
 
256
- #
257
273
  # This is rather low-level use #transaction and a block for a higher-level
258
274
  # technique.
259
275
  #
@@ -264,7 +280,6 @@ module Rufus::Edo
264
280
  @db.trancommit
265
281
  end
266
282
 
267
- #
268
283
  # This is rather low-level use #transaction and a block for a higher-level
269
284
  # technique.
270
285
  #
@@ -66,7 +66,6 @@ module Rufus::Edo
66
66
  include Rufus::Edo::CabinetCore
67
67
  include Rufus::Tokyo::CabinetConfig
68
68
 
69
- #
70
69
  # Initializes and open a cabinet (hash, b+ tree or fixed-size)
71
70
  #
72
71
  # db = Rufus::Edo::Cabinet.new('data.tch')
@@ -136,6 +135,9 @@ module Rufus::Edo
136
135
  # * :capnum specifies the capacity number of records.
137
136
  # * :capsiz specifies the capacity size of using memory.
138
137
  #
138
+ # * :dfunit unit step number. If it is not more than 0,
139
+ # the auto defragmentation is disabled. (Since TC 1.4.21)
140
+ #
139
141
  #
140
142
  # = NOTE :
141
143
  #
@@ -182,10 +184,17 @@ module Rufus::Edo
182
184
 
183
185
  @db.setxmsiz(conf[:xmsiz]) unless conf[:type] == :fixed
184
186
 
187
+ #
188
+ # set dfunit (TC > 1.4.21)
189
+
190
+ @db.setdfunit(conf[:dfunit]) if @db.respond_to?(:setdfunit)
191
+
185
192
  #
186
193
  # open
187
194
 
188
- @db.open(conf[:path], conf[:mode]) || raise_error
195
+ @path = conf[:path]
196
+
197
+ @db.open(@path, conf[:mode]) || raise_error
189
198
 
190
199
  #
191
200
  # default
@@ -58,7 +58,6 @@ module Rufus::Edo
58
58
  include Rufus::Tokyo::CabinetConfig
59
59
  include Rufus::Edo::TableCore
60
60
 
61
- #
62
61
  # Initializes and open a table.
63
62
  #
64
63
  # db = Rufus::Edo::Table.new('data.tct')
@@ -99,6 +98,9 @@ module Rufus::Edo
99
98
  # cached. If it is not more than 0, the default value is
100
99
  # specified. The default value is 512.
101
100
  #
101
+ # * :dfunit unit step number. If it is not more than 0,
102
+ # the auto defragmentation is disabled. (Since TC 1.4.21)
103
+ #
102
104
  # = NOTE :
103
105
  #
104
106
  # On reopening a file, Cabinet will tend to stick to the parameters as
@@ -126,15 +128,30 @@ module Rufus::Edo
126
128
 
127
129
  @db.setxmsiz(conf[:xmsiz])
128
130
 
131
+ #
132
+ # set dfunit (TC > 1.4.21)
133
+
134
+ @db.setdfunit(conf[:dfunit]) if @db.respond_to?(:setdfunit)
135
+
129
136
  #
130
137
  # open
131
138
 
132
- @db.open(conf[:path], conf[:mode]) || raise_error
139
+ @path = conf[:path]
140
+
141
+ @db.open(@path, conf[:mode]) || raise_error
142
+ end
143
+
144
+ # Returns the path to this table.
145
+ #
146
+ def path
147
+
148
+ @path
133
149
  end
134
150
 
135
151
  protected
136
152
 
137
153
  def table_query_class #:nodoc#
154
+
138
155
  TokyoCabinet::TDBQRY
139
156
  end
140
157
  end
@@ -97,6 +97,19 @@ module Rufus::Edo
97
97
  end
98
98
  end
99
99
 
100
+ # This implementation of lget relies on the mget provided by
101
+ # Hirabayashi-san in his native ruby library (all the other rufus
102
+ # tables do multiple gets for now)
103
+ #
104
+ def lget (keys)
105
+
106
+ h = keys.inject({}) { |h, k| h[k] = nil; h }
107
+ r = @db.mget(h)
108
+
109
+ raise 'lget failure' if r == -1
110
+ h
111
+ end
112
+
100
113
  def transaction #:nodoc#
101
114
  raise NoMethodError.new("NetTyrant : transactions not supported")
102
115
  end
@@ -38,7 +38,6 @@ module Rufus::Edo
38
38
  include Rufus::Tokyo::HashMethods
39
39
  include Rufus::Tokyo::Transactions
40
40
 
41
- #
42
41
  # Closes the table (and frees the datastructure allocated for it),
43
42
  # raises an exception in case of failure.
44
43
  #
@@ -46,7 +45,6 @@ module Rufus::Edo
46
45
  @db.close || raise_error
47
46
  end
48
47
 
49
- #
50
48
  # Generates a unique id (in the context of this Table instance)
51
49
  #
52
50
  def generate_unique_id
@@ -62,7 +60,6 @@ module Rufus::Edo
62
60
  :keep => 1 << 24
63
61
  }
64
62
 
65
- #
66
63
  # Sets an index on a column of the table.
67
64
  #
68
65
  # Types maybe be :lexical or :decimal, use :keep to "add" and
@@ -81,7 +78,6 @@ module Rufus::Edo
81
78
  @db.setindex(column_name, i) || raise_error
82
79
  end
83
80
 
84
- #
85
81
  # Inserts a record in the table db
86
82
  #
87
83
  # table['pk0'] = [ 'name', 'fred', 'age', '45' ]
@@ -102,7 +98,6 @@ module Rufus::Edo
102
98
  @db.put(pk, m) || raise_error
103
99
  end
104
100
 
105
- #
106
101
  # Removes an entry in the table
107
102
  #
108
103
  # (might raise an error if the delete itself failed, but returns nil
@@ -121,7 +116,6 @@ module Rufus::Edo
121
116
  val
122
117
  end
123
118
 
124
- #
125
119
  # Removes all records in this table database
126
120
  #
127
121
  # Raises an error if something went wrong
@@ -131,7 +125,6 @@ module Rufus::Edo
131
125
  @db.vanish || raise_error
132
126
  end
133
127
 
134
- #
135
128
  # Returns an array of all the primary keys in the table
136
129
  #
137
130
  # With no options given, this method will return all the keys (strings)
@@ -165,7 +158,6 @@ module Rufus::Edo
165
158
  end
166
159
  end
167
160
 
168
- #
169
161
  # Deletes all the entries whose key begin with the given prefix.
170
162
  #
171
163
  def delete_keys_with_prefix (prefix)
@@ -174,7 +166,17 @@ module Rufus::Edo
174
166
  ks.each { |k| self.delete(k) }
175
167
  end
176
168
 
169
+ # No 'misc' methods for the table library, so this lget is equivalent
170
+ # to calling get for each key. Hoping later versions of TC will provide
171
+ # a mget method.
177
172
  #
173
+ def lget (keys)
174
+
175
+ # TODO : maybe investigate a query on the column 'primary_key' ?
176
+
177
+ keys.inject({}) { |h, k| v = self[k]; h[k] = v if v; h }
178
+ end
179
+
178
180
  # Returns the number of records in this table db
179
181
  #
180
182
  def size
@@ -182,7 +184,6 @@ module Rufus::Edo
182
184
  @db.rnum
183
185
  end
184
186
 
185
- #
186
187
  # Prepares a query instance (block is optional)
187
188
  #
188
189
  def prepare_query (&block)
@@ -191,7 +192,6 @@ module Rufus::Edo
191
192
  q
192
193
  end
193
194
 
194
- #
195
195
  # Prepares and runs a query, returns an array of hashes (all Ruby)
196
196
  # (takes care of freeing the query and the result set structures)
197
197
  #
@@ -200,7 +200,6 @@ module Rufus::Edo
200
200
  prepare_query(&block).run
201
201
  end
202
202
 
203
- #
204
203
  # Warning : this method is low-level, you probably only need
205
204
  # to use #transaction and a block.
206
205
  #
@@ -211,7 +210,6 @@ module Rufus::Edo
211
210
  @db.tranbegin || raise_error
212
211
  end
213
212
 
214
- #
215
213
  # Warning : this method is low-level, you probably only need
216
214
  # to use #transaction and a block.
217
215
  #
@@ -222,7 +220,6 @@ module Rufus::Edo
222
220
  @db.trancommit || raise_error
223
221
  end
224
222
 
225
- #
226
223
  # Warning : this method is low-level, you probably only need
227
224
  # to use #transaction and a block.
228
225
  #
@@ -233,7 +230,6 @@ module Rufus::Edo
233
230
  @db.tranabort || raise_error
234
231
  end
235
232
 
236
- #
237
233
  # Returns the underlying 'native' Ruby object (of the class devised by
238
234
  # Hirabayashi-san)
239
235
  #
@@ -244,7 +240,6 @@ module Rufus::Edo
244
240
 
245
241
  protected
246
242
 
247
- #
248
243
  # Returns the value (as a Ruby Hash) else nil
249
244
  #
250
245
  # (the actual #[] method is provided by HashMethods)
@@ -254,7 +249,6 @@ module Rufus::Edo
254
249
  @db.get(k)
255
250
  end
256
251
 
257
- #
258
252
  # Obviously something went wrong, let's ask the db about it and raise
259
253
  # an EdoError
260
254
  #
@@ -286,7 +280,6 @@ module Rufus::Edo
286
280
 
287
281
  include Rufus::Tokyo::QueryConstants
288
282
 
289
- #
290
283
  # Creates a query for a given Rufus::Tokyo::Table
291
284
  #
292
285
  # Queries are usually created via the #query (#prepare_query #do_query)
@@ -311,7 +304,6 @@ module Rufus::Edo
311
304
  @opts = {}
312
305
  end
313
306
 
314
- #
315
307
  # Adds a condition
316
308
  #
317
309
  # table.query { |q|
@@ -379,7 +371,6 @@ module Rufus::Edo
379
371
  end
380
372
  alias :add_condition :add
381
373
 
382
- #
383
374
  # Sets the max number of records to return for this query.
384
375
  #
385
376
  # (If you're using TC >= 1.4.10 the optional 'offset' (skip) parameter
@@ -392,7 +383,6 @@ module Rufus::Edo
392
383
  @query.setmax(i)
393
384
  end
394
385
 
395
- #
396
386
  # Sets the sort order for the result of the query
397
387
  #
398
388
  # The 'direction' may be :
@@ -409,7 +399,6 @@ module Rufus::Edo
409
399
  @query.setorder(colname, DIRECTIONS[direction])
410
400
  end
411
401
 
412
- #
413
402
  # When set to true, only the primary keys of the matching records will
414
403
  # be returned.
415
404
  #
@@ -418,7 +407,6 @@ module Rufus::Edo
418
407
  @opts[:pk_only] = on
419
408
  end
420
409
 
421
- #
422
410
  # When set to true, the :pk (primary key) is not inserted in the record
423
411
  # (hashes) returned
424
412
  #
@@ -427,14 +415,12 @@ module Rufus::Edo
427
415
  @opts[:no_pk] = on
428
416
  end
429
417
 
430
- #
431
418
  # Runs this query (returns a TableResultSet instance)
432
419
  #
433
420
  def run
434
421
  @last_resultset = TableResultSet.new(@table, @query.search, @opts)
435
422
  end
436
423
 
437
- #
438
424
  # Returns the count of results this query return when last run.
439
425
  # Returns 0 if the query was not yet run.
440
426
  #
@@ -446,7 +432,6 @@ module Rufus::Edo
446
432
  @last_resultset ? @last_resultset.size : 0
447
433
  end
448
434
 
449
- #
450
435
  # Frees this data structure
451
436
  #
452
437
  def free
@@ -471,7 +456,6 @@ module Rufus::Edo
471
456
  @opts = query_opts
472
457
  end
473
458
 
474
- #
475
459
  # Returns the count of element in this result set
476
460
  #
477
461
  def size
@@ -481,7 +465,6 @@ module Rufus::Edo
481
465
 
482
466
  alias :length :size
483
467
 
484
- #
485
468
  # The classical each
486
469
  #
487
470
  def each
@@ -497,7 +480,6 @@ module Rufus::Edo
497
480
  end
498
481
  end
499
482
 
500
- #
501
483
  # Returns an array of hashes
502
484
  #
503
485
  def to_a
@@ -505,7 +487,6 @@ module Rufus::Edo
505
487
  self.collect { |m| m }
506
488
  end
507
489
 
508
- #
509
490
  # Frees this query (the underlying Tokyo Cabinet list structure)
510
491
  #
511
492
  def free