rrudb 0.0.2 → 0.0.3

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
  SHA256:
3
- metadata.gz: 97365f391776500be966ed6f9549b86e56121cb688ea6875bd6cba2e7d39dbcb
4
- data.tar.gz: 364d820a47146a01a2d969111b1e044ec80bc8e02f2887b5c1c49678b4a60551
3
+ metadata.gz: f370cffff83adbbec822fdeb83d4cd96e768351fb0a592473d1aeddafaa7d413
4
+ data.tar.gz: 52413e39845297cd3c63ff23309645795a2145d7252b99327d9a4c9778047c38
5
5
  SHA512:
6
- metadata.gz: 6fcef1c9c4e036e881ba4805ede5579e6eed788f7ed6d5fa3af93888ce55d284751f8ed555809e6ecedcf2f0e478e76d252bcefd4047014c12d7feaa19067327
7
- data.tar.gz: 880d565f2aac8e0ac3821c495a9c52eb82baae3acf10fdf7601c578ed3f4d4ad1b12dd269ff490c47cfc8222d4395d507d7b78e5b288aead70373fa7b8bffc58
6
+ metadata.gz: 4bd35fd8dae07048ce9889453b7b70197a95cf7b6aef3c81e2dbb91ce887cb618fa85bc800ac4ac542fd4867b424a4c1fc6456861e6a8795ac9b1b68f5ad208b
7
+ data.tar.gz: 5038eae0823c6ba1c465976e07008e746fff3865165ce22b6eecf4024c14622b880eabca77281261deaef4e56e39e652f9eb687f7a18db1b83ee436423bc5f3d
data/examples/each.rb ADDED
@@ -0,0 +1,37 @@
1
+ require 'rudb'
2
+
3
+ N = 10
4
+ KEY_SIZE = 32/8 # => sizeof(uint32_t) = 4 bytes
5
+
6
+ dat_path = 'db.dat'
7
+ key_path = 'db.key'
8
+ log_path = 'db.log'
9
+
10
+ RuDB::create :dat_path => dat_path,
11
+ :key_path => key_path,
12
+ :log_path => log_path,
13
+ :app_num => 1,
14
+ :salt => RuDB::make_salt,
15
+ :key_size => KEY_SIZE,
16
+ :block_size => RuDB::block_size('.'),
17
+ :load_factor => 0.5
18
+
19
+ db = RuDB::Store.new
20
+ db.open(dat_path, key_path, log_path)
21
+
22
+ 0.upto(N) { |i|
23
+ kv = [i].pack("L")
24
+ db.insert(kv, kv)
25
+ }
26
+
27
+ db.close
28
+
29
+ RuDB::each(dat_path) { |key, value|
30
+ uk = key.unpack("L").first
31
+ uv = value.unpack("L").first
32
+ puts "#{uk}: #{uv}"
33
+ }
34
+
35
+ RuDB::erase_file dat_path
36
+ RuDB::erase_file key_path
37
+ RuDB::erase_file log_path
data/ext/rudb/rudb.cpp CHANGED
@@ -99,6 +99,24 @@ VALUE rudb_block_size(VALUE _self, VALUE _path) {
99
99
  return INT2NUM(nudb::block_size(path));
100
100
  }
101
101
 
102
+ // TODO parameterize progress callback
103
+ VALUE rudb_visit(VALUE _self, VALUE path, VALUE callback){
104
+ Check_Type(path, T_STRING);
105
+ std::string _path = std::string((char*)RSTRING_PTR(path), RSTRING_LEN(path));
106
+
107
+ nudb::error_code ec;
108
+ nudb::visit(_path, [&](void const* key, std::size_t key_size,
109
+ void const* val, std::size_t val_size,
110
+ nudb::error_code& ec1){
111
+ VALUE key_str = rb_str_new((char const*)key, key_size);
112
+ VALUE val_str = rb_str_new((char const*)val, val_size);
113
+
114
+ rb_funcall(callback, rb_intern("call"), 2, key_str, val_str);
115
+ }, nudb::no_progress{}, ec);
116
+
117
+ return ec2obj(new nudb::error_code(ec));
118
+ }
119
+
102
120
  ///
103
121
 
104
122
  void db_free(nudb_store_pointer* store_pointer){
@@ -218,6 +236,7 @@ extern "C"{
218
236
  rb_define_singleton_method(mRuDB, "erase_file", (METHOD)rudb_erase_file, 1);
219
237
  rb_define_singleton_method(mRuDB, "make_salt", (METHOD)rudb_make_salt, 0);
220
238
  rb_define_singleton_method(mRuDB, "block_size", (METHOD)rudb_block_size, 1);
239
+ rb_define_singleton_method(mRuDB, "visit", (METHOD)rudb_visit, 2);
221
240
 
222
241
  cRuDB_store = rb_define_class_under(mRuDB, "Store", rb_cObject);
223
242
  rb_define_alloc_func(cRuDB_store, store_alloc);
data/lib/rudb/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RuDB
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end # module RuDB
data/lib/rudb.rb CHANGED
@@ -1 +1,9 @@
1
1
  require 'rudb.so'
2
+
3
+ module RuDB
4
+ def self.each(path)
5
+ RuDB::visit(path, proc { |key, val|
6
+ yield key, val
7
+ })
8
+ end
9
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rrudb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dev Null Productions
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-14 00:00:00.000000000 Z
11
+ date: 2019-05-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby NuDB Wrapper
14
14
  email:
@@ -21,6 +21,7 @@ files:
21
21
  - ".yardopts"
22
22
  - LICENSE.txt
23
23
  - README.md
24
+ - examples/each.rb
24
25
  - examples/example.rb
25
26
  - ext/rudb/NuDB/include/nudb/CMakeLists.txt
26
27
  - ext/rudb/NuDB/include/nudb/_experimental/basic_seconds_clock.hpp