rocksdb-ruby 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 508079e41f7fdac06ebdb734ef57f74af0ea97cc
4
- data.tar.gz: 0887f5b646875890f6fd08707c404e9ae9724ac4
3
+ metadata.gz: 96d67a886d0334375d5cb1e0b467231dc021d42b
4
+ data.tar.gz: 4d7dd5d7f9b5bb9abaa97e9b5ea253b88ea172d8
5
5
  SHA512:
6
- metadata.gz: 019a972398e9c9a331eed14e1a24dc17521c66e036c4dbad999e4c6fe4500f0c36305164384140dbcc91455882352ff7106b5a274400d6780fc19d5789b7c54f
7
- data.tar.gz: 9e6f2e227742dc9f7f205fbbc9cf353f17c444ead0e0d5a5756520dd64742dd0316c53dbb9f245c4d75c06708c60483a0069a8723e269c0a0c56226d68b36a10
6
+ metadata.gz: 3be5427f297b326a9a37d2aa9f336071b3a19e1fac2455d5b958a67df79cf5b26f8b97bf22c424a66befff7890828ea7062b6c084ce63a5114dd69543a1a590a
7
+ data.tar.gz: b8df25ee30ec7f83ea9f5af9731020cc7ed21365c0a611638fee0312f332a3019b5caed9cfdf83388d25d6d9a8393298278e445688e0e158633e91a2fc7e4d0f
data/README.md CHANGED
@@ -51,6 +51,15 @@ Or install it yourself as:
51
51
  end
52
52
  iterator.close
53
53
 
54
+ #Block
55
+ rocksdb.each do |data|
56
+ puts data
57
+ end
58
+
59
+ #Hash access
60
+ rocksdb['key'] = data
61
+ puts rocksdb['key']
62
+
54
63
 
55
64
  rocksdb.close
56
65
 
@@ -5,7 +5,7 @@ RbConfig::CONFIG["CPP"] = "g++ -E -std=gnu++11"
5
5
 
6
6
  if have_header('rocksdb/db.h') and have_library('rocksdb')
7
7
  $CPPFLAGS << " -std=gnu++11"
8
- create_makefile("RocksDB")
8
+ create_makefile("RocksDB/RocksDB")
9
9
  else
10
10
  abort "can't find header or library of rocksdb"
11
11
  end
@@ -27,7 +27,7 @@ extern "C" {
27
27
 
28
28
  VALUE db_alloc(VALUE klass){
29
29
  rocksdb_pointer* db_pointer = ALLOC(rocksdb_pointer);
30
- return Data_Wrap_Struct(klass, 0, -1, db_pointer);
30
+ return Data_Wrap_Struct(klass, 0, db_free, db_pointer);
31
31
  }
32
32
 
33
33
  VALUE rocksdb_db_put(VALUE self, VALUE v_key, VALUE v_value) {
@@ -91,7 +91,7 @@ extern "C" {
91
91
 
92
92
  status = db_pointer->db->MultiGet(rocksdb::ReadOptions(),keys,&values);
93
93
  for(i=0; i < length; i++){
94
- RARRAY_PTR(v_array)[i] = rb_str_new(values[i].data(), values[i].size());
94
+ RARRAY_PTR(v_array)[i] = rb_enc_str_new(values[i].data(), values[i].size(), rb_utf8_encoding());
95
95
  }
96
96
  return v_array;
97
97
  }
@@ -124,10 +124,19 @@ extern "C" {
124
124
  rocksdb_pointer* db_pointer;
125
125
  Data_Get_Struct(self, rocksdb_pointer, db_pointer);
126
126
 
127
- delete db_pointer->db;
127
+ db_free(db_pointer);
128
128
  return Qnil;
129
129
  }
130
130
 
131
+ void db_free(rocksdb_pointer* db_pointer){
132
+ std::cout << "free\n";
133
+ if(db_pointer->db != NULL){
134
+ delete db_pointer->db;
135
+ db_pointer->db = NULL;
136
+ }
137
+ delete db_pointer;
138
+ }
139
+
131
140
  VALUE rocksdb_db_new_iterator(VALUE self){
132
141
  rocksdb_pointer* db_pointer;
133
142
  rocksdb_iterator_pointer* rocksdb_it;
@@ -146,23 +155,20 @@ extern "C" {
146
155
 
147
156
 
148
157
  VALUE rocksdb_db_each(VALUE self){
158
+ if(!rb_block_given_p()){
159
+ return rocksdb_db_new_iterator(self);
160
+ }
161
+
149
162
  rocksdb_pointer* db_pointer;
150
163
  Data_Get_Struct(self, rocksdb_pointer, db_pointer);
151
164
  rocksdb::Iterator* it = db_pointer->db->NewIterator(rocksdb::ReadOptions());
152
165
 
153
- long i;
154
- volatile VALUE ary = rb_ary_new();
155
-
156
- i = 0;
157
166
  for (it->SeekToFirst(); it->Valid(); it->Next()) {
158
- VALUE v = rb_enc_str_new(it->value().data(), it->value().size(), rb_utf8_encoding());
159
- rb_ary_store(ary, i, v);
160
- rb_yield(RARRAY_PTR(ary)[i]);
161
- i++;
167
+ rb_yield(rb_enc_str_new(it->value().data(), it->value().size(), rb_utf8_encoding()));
162
168
  }
169
+
163
170
  delete it;
164
-
165
- return ary;
171
+ return self;
166
172
  }
167
173
 
168
174
  VALUE rocksdb_db_reverse_each(VALUE self){
@@ -170,20 +176,12 @@ extern "C" {
170
176
  Data_Get_Struct(self, rocksdb_pointer, db_pointer);
171
177
  rocksdb::Iterator* it = db_pointer->db->NewIterator(rocksdb::ReadOptions());
172
178
 
173
- long i;
174
- volatile VALUE ary = rb_ary_new();
175
-
176
- i = 0;
177
179
  for (it->SeekToLast(); it->Valid(); it->Prev()) {
178
- VALUE v = rb_enc_str_new(it->value().data(), it->value().size(), rb_utf8_encoding());
179
- rb_ary_store(ary, i, v);
180
- rb_yield(RARRAY_PTR(ary)[i]);
181
- i++;
180
+ rb_yield(rb_enc_str_new(it->value().data(), it->value().size(), rb_utf8_encoding()));
182
181
  }
182
+
183
183
  delete it;
184
-
185
- return ary;
186
-
184
+ return self;
187
185
  }
188
186
 
189
187
  VALUE rocksdb_db_debug(VALUE self){
@@ -17,5 +17,5 @@ extern "C" {
17
17
  VALUE rocksdb_db_each(VALUE self);
18
18
  VALUE rocksdb_db_each_index(VALUE self);
19
19
  VALUE rocksdb_db_reverse_each(VALUE self);
20
-
20
+ void db_free(rocksdb_pointer* db_pointer);
21
21
  }
@@ -1,5 +1,5 @@
1
1
  module Rocksdb
2
2
  module Ruby
3
- VERSION = "0.0.8"
3
+ VERSION = "0.0.9"
4
4
  end
5
5
  end
@@ -63,9 +63,12 @@ describe RocksDB do
63
63
  @rocksdb.put("test:japanese", "あいうえお")
64
64
 
65
65
  expect(@rocksdb.get("test:japanese")).to eq "あいうえお"
66
+ expect(@rocksdb.multi_get(["test:japanese"])).to eq ["あいうえお"]
66
67
  end
67
68
 
68
69
  it 'should use each' do
70
+ iter = @rocksdb.each
71
+
69
72
  array = []
70
73
  @rocksdb.each do |value|
71
74
  expect(value).not_to be_empty
@@ -79,7 +82,7 @@ describe RocksDB do
79
82
  end
80
83
 
81
84
  expect(array).to eq rev_array.reverse
82
-
85
+ iter.close
83
86
  end
84
87
 
85
88
  it 'should exists?' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rocksdb-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Isamu Arimoto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-04 00:00:00.000000000 Z
11
+ date: 2014-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler