rocksdb-ruby 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2e6ff2cad354cadc31a44416ef54a7d34f1d3378
4
- data.tar.gz: 9c9ec1928f6528ee8d0d5ca65280cdaa0d577ef4
3
+ metadata.gz: b3d3d57184046e4127d2d843d04e549d85547311
4
+ data.tar.gz: d062ed4026b6469c6f14a6788894d442e648bf93
5
5
  SHA512:
6
- metadata.gz: 16d1135da6af3589a3a7d99d1ab2da714a353fb3286e7ed9f70fa540a3079719396be9a5512719890d89df9bc074303be04c8b8eb105eb1f175680c33e472168
7
- data.tar.gz: 80e078c1ac478de2e77527d532080efb127d992ab77505e8924da3c9c0ca65d18cf044c318320823c995744ecd184c2957bc91ae8774e2a5c9b579f6f763f613
6
+ metadata.gz: 2f650e958abed13456d2967404041de91a08da1ee303def9f16cc9abfbc8a5e4a6143daac8cdc922e7a0d1970e91c7fab5cbe4843c27b51fc63a9c231a9a4485
7
+ data.tar.gz: 12e3da582a353960c906e1b4cc76a5f1d0a84fb7ada488d0d6ed5bd6f91754e26d27625e0e45c1b5d48c67e9a3cecc2657b9e048cd0379ded83e3f5607b13980
@@ -28,7 +28,12 @@ extern "C" {
28
28
  if(v == Qtrue){
29
29
  readonly = true;
30
30
  }
31
+ set_opt(&options, &v_options);
31
32
  }
33
+ //std::cout << options.max_bytes_for_level_base << "\n";
34
+ //std::cout << options.max_grandparent_overlap_factor << "\n";
35
+ //std::cout << options.delete_obsolete_files_period_micros << "\n";
36
+
32
37
  options.create_if_missing = true;
33
38
  if(readonly){
34
39
  status = rocksdb::DB::OpenForReadOnly(options, db_file_name, &db);
@@ -41,6 +46,26 @@ extern "C" {
41
46
  return status.ok() ? Qtrue : Qfalse;
42
47
  }
43
48
 
49
+ void set_opt_unit_val(uint64_t* opt, char* name, VALUE *v_options){
50
+
51
+ VALUE v2 = rb_hash_aref(*v_options, ID2SYM(rb_intern(name)));
52
+ if(RB_TYPE_P(v2, T_FIXNUM)){
53
+ *opt = NUM2INT(v2);
54
+ }
55
+ }
56
+ void set_opt_int_val(int* opt, char* name, VALUE *v_options){
57
+ VALUE v2 = rb_hash_aref(*v_options, ID2SYM(rb_intern(name)));
58
+ if(RB_TYPE_P(v2, T_FIXNUM)){
59
+ *opt = NUM2INT(v2);
60
+ }
61
+ }
62
+
63
+ void set_opt(rocksdb::Options* options, VALUE *v_options){
64
+ set_opt_unit_val(&options->max_bytes_for_level_base, (char *) "max_bytes_for_level_base", v_options);
65
+ set_opt_int_val(&options->max_grandparent_overlap_factor, (char *) "max_grandparent_overlap_factor", v_options);
66
+ set_opt_unit_val(&options->delete_obsolete_files_period_micros, (char *) "delete_obsolete_files_period_micros", v_options);
67
+ }
68
+
44
69
  VALUE db_alloc(VALUE klass){
45
70
  rocksdb_pointer* db_pointer = ALLOC(rocksdb_pointer);
46
71
  return Data_Wrap_Struct(klass, 0, db_free, db_pointer);
@@ -189,6 +214,44 @@ extern "C" {
189
214
  return self;
190
215
  }
191
216
 
217
+ VALUE rocksdb_db_each_index(VALUE self){
218
+ if(!rb_block_given_p()){
219
+ return rocksdb_db_new_iterator(self);
220
+ }
221
+
222
+ rocksdb_pointer* db_pointer;
223
+ Data_Get_Struct(self, rocksdb_pointer, db_pointer);
224
+ rocksdb::Iterator* it = db_pointer->db->NewIterator(rocksdb::ReadOptions());
225
+
226
+ for (it->SeekToFirst(); it->Valid(); it->Next()) {
227
+ rb_yield(rb_enc_str_new(it->key().data(), it->key().size(), rb_utf8_encoding()));
228
+ }
229
+
230
+ delete it;
231
+ return self;
232
+ }
233
+
234
+ VALUE rocksdb_db_each_with_index(VALUE self){
235
+ if(!rb_block_given_p()){
236
+ return rocksdb_db_new_iterator(self);
237
+ }
238
+
239
+ rocksdb_pointer* db_pointer;
240
+ Data_Get_Struct(self, rocksdb_pointer, db_pointer);
241
+ rocksdb::Iterator* it = db_pointer->db->NewIterator(rocksdb::ReadOptions());
242
+
243
+ for (it->SeekToFirst(); it->Valid(); it->Next()) {
244
+ VALUE a = rb_enc_str_new(it->key().data(), it->key().size(), rb_utf8_encoding());
245
+ VALUE b = rb_enc_str_new(it->value().data(), it->value().size(), rb_utf8_encoding());
246
+ rb_yield_values(2, a, b);
247
+ }
248
+
249
+ delete it;
250
+ return self;
251
+ }
252
+
253
+
254
+
192
255
  VALUE rocksdb_db_reverse_each(VALUE self){
193
256
  rocksdb_pointer* db_pointer;
194
257
  Data_Get_Struct(self, rocksdb_pointer, db_pointer);
@@ -16,6 +16,10 @@ extern "C" {
16
16
  VALUE rocksdb_db_new_iterator(VALUE self);
17
17
  VALUE rocksdb_db_each(VALUE self);
18
18
  VALUE rocksdb_db_each_index(VALUE self);
19
+ VALUE rocksdb_db_each_with_index(VALUE self);
19
20
  VALUE rocksdb_db_reverse_each(VALUE self);
20
21
  void db_free(rocksdb_pointer* db_pointer);
22
+ void set_opt(rocksdb::Options* opt, VALUE *v_options);
23
+ void set_opt_unit_val(uint64_t* opt, char* name, VALUE *v_options);
24
+ void set_opt_int_val(int* opt, char* name, VALUE *v_options);
21
25
  }
@@ -32,6 +32,8 @@ extern "C" {
32
32
  rb_define_method(cRocksdb_db, "new_iterator", (METHOD)rocksdb_db_new_iterator, 0);
33
33
 
34
34
  rb_define_method(cRocksdb_db, "each", (METHOD)rocksdb_db_each, 0);
35
+ rb_define_method(cRocksdb_db, "each_index", (METHOD)rocksdb_db_each_index, 0);
36
+ rb_define_method(cRocksdb_db, "each_with_index", (METHOD)rocksdb_db_each_with_index, 0);
35
37
  rb_define_method(cRocksdb_db, "reverse_each", (METHOD)rocksdb_db_reverse_each, 0);
36
38
 
37
39
  cRocksdb_write_batch = rb_define_class_under(cRocksdb, "Batch", rb_cObject);
@@ -1,5 +1,5 @@
1
1
  module Rocksdb
2
2
  module Ruby
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -0,0 +1,18 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+ require "rocksdb"
4
+
5
+ describe RocksDB do
6
+ before do
7
+ @rocksdb = RocksDB::DB.new "/tmp/file3", {:max_bytes_for_level_base => 10485760, :max_grandparent_overlap_factor => 20}
8
+ end
9
+
10
+ it 'should get data' do
11
+ @rocksdb.put("test:multi_db", "10")
12
+ expect(@rocksdb.get("test:multi_db")).to eq "10"
13
+ end
14
+
15
+ after do
16
+ @rocksdb.close
17
+ end
18
+ end
data/spec/db_spec.rb CHANGED
@@ -81,8 +81,19 @@ describe RocksDB do
81
81
  expect(value).not_to be_empty
82
82
  rev_array << value
83
83
  end
84
+
84
85
 
85
86
  expect(array).to eq rev_array.reverse
87
+
88
+ @rocksdb.each_index do |key|
89
+ expect(key).not_to be_empty
90
+ end
91
+
92
+ @rocksdb.each_with_index do |key, value|
93
+ expect(key).not_to be_empty
94
+ expect(value).not_to be_empty
95
+ end
96
+
86
97
  iter.close
87
98
  end
88
99
 
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.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Isamu Arimoto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-29 00:00:00.000000000 Z
11
+ date: 2015-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,7 @@ files:
80
80
  - lib/rocksdb/ruby.rb
81
81
  - lib/rocksdb/ruby/version.rb
82
82
  - rocksdb-ruby.gemspec
83
+ - spec/db_options_spec.rb
83
84
  - spec/db_readonly_spec.rb
84
85
  - spec/db_spec.rb
85
86
  - spec/iterator_spec.rb
@@ -105,11 +106,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
106
  version: '0'
106
107
  requirements: []
107
108
  rubyforge_project:
108
- rubygems_version: 2.0.3
109
+ rubygems_version: 2.4.6
109
110
  signing_key:
110
111
  specification_version: 4
111
112
  summary: A simple RocksDB library for Ruby
112
113
  test_files:
114
+ - spec/db_options_spec.rb
113
115
  - spec/db_readonly_spec.rb
114
116
  - spec/db_spec.rb
115
117
  - spec/iterator_spec.rb