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 +4 -4
- data/README.md +9 -0
- data/ext/rocksdb/extconf.rb +1 -1
- data/ext/rocksdb/rocksdb_db_rb.cc +22 -24
- data/ext/rocksdb/rocksdb_db_rb.h +1 -1
- data/lib/rocksdb/ruby/version.rb +1 -1
- data/spec/db_spec.rb +4 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96d67a886d0334375d5cb1e0b467231dc021d42b
|
4
|
+
data.tar.gz: 4d7dd5d7f9b5bb9abaa97e9b5ea253b88ea172d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3be5427f297b326a9a37d2aa9f336071b3a19e1fac2455d5b958a67df79cf5b26f8b97bf22c424a66befff7890828ea7062b6c084ce63a5114dd69543a1a590a
|
7
|
+
data.tar.gz: b8df25ee30ec7f83ea9f5af9731020cc7ed21365c0a611638fee0312f332a3019b5caed9cfdf83388d25d6d9a8393298278e445688e0e158633e91a2fc7e4d0f
|
data/README.md
CHANGED
data/ext/rocksdb/extconf.rb
CHANGED
@@ -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,
|
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] =
|
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
|
-
|
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
|
-
|
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
|
-
|
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){
|
data/ext/rocksdb/rocksdb_db_rb.h
CHANGED
data/lib/rocksdb/ruby/version.rb
CHANGED
data/spec/db_spec.rb
CHANGED
@@ -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.
|
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:
|
11
|
+
date: 2014-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|