dartsclone 0.1.0 → 0.2.0

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: ffd79764c75c8fd8c2b7dc55b5f80c3875a0641420f05a9d1e07d701ffc15a17
4
- data.tar.gz: 70799ddcdb885b78fa338a36b28063df1ae41a0f87d3be6a1aad8faec8b939a7
3
+ metadata.gz: dce86b5df78cc6b62be497a33f5203a352def9f83767191840e2cd5f2bcae460
4
+ data.tar.gz: da2b74859ccc9834583b33ac4c9628b976a6e329b9a8d77348b4947767503794
5
5
  SHA512:
6
- metadata.gz: af070c15bc7b53a58d06200a2a8da7ce931161c470248f43a80365af3323122db200fa467bce0fe738d5ecfbd1dde8865733c37a27dcf7d00f5c8947341feeef
7
- data.tar.gz: d4bad89bbbb9b2a7c8aa0defb663e56db7cbdae2a934308ebb86c8ad4ddc24a8d659722186b1ce9de4ce1f4faeaefb17821f1564ec54865e668813ca06617994
6
+ metadata.gz: 074b992e52c7604970772c30976cbbe4cf8efd7f7cb6d26dcf62e8f3eb2998b4cb08dd615ab224809786cd1f65fc4759f80fe3d8ba53e4674a17afe25188b43d
7
+ data.tar.gz: 0d136b219466c196dbb9616b02f01ab98b3225fef93831e6e80aefa049561aab621073fa6ac6589e3132b71e803eb65c0f0f1474a9047be62093e58ce426594a
@@ -1,2 +1,5 @@
1
+ ## 0.2.0
2
+ - Add get_array and set_array methods to dump and load array data.
3
+
1
4
  ## 0.1.0
2
5
  - First release.
@@ -30,6 +30,8 @@ class RbDoubleArray
30
30
  rb_define_method(rb_cDoubleArray, "build", RUBY_METHOD_FUNC(_double_array_build), -1);
31
31
  rb_define_method(rb_cDoubleArray, "open", RUBY_METHOD_FUNC(_double_array_open), -1);
32
32
  rb_define_method(rb_cDoubleArray, "save", RUBY_METHOD_FUNC(_double_array_save), -1);
33
+ rb_define_method(rb_cDoubleArray, "get_array", RUBY_METHOD_FUNC(_double_array_get_array), 0);
34
+ rb_define_method(rb_cDoubleArray, "set_array", RUBY_METHOD_FUNC(_double_array_set_array), 1);
33
35
  rb_define_method(rb_cDoubleArray, "exact_match_search", RUBY_METHOD_FUNC(_double_array_exact_match_search), -1);
34
36
  rb_define_method(rb_cDoubleArray, "common_prefix_search", RUBY_METHOD_FUNC(_double_array_common_prefix_search), -1);
35
37
  rb_define_method(rb_cDoubleArray, "traverse", RUBY_METHOD_FUNC(_double_array_traverse), -1);
@@ -90,8 +92,8 @@ class RbDoubleArray
90
92
 
91
93
  const char* filename = StringValueCStr(_filename);
92
94
  const char* mode = kwvalues[0] == Qundef ? "rb" : StringValueCStr(kwvalues[0]);
93
- const size_t offset = kwvalues[1] == Qundef ? 0 : (size_t)NUM2INT(kwvalues[1]);
94
- const size_t size = kwvalues[2] == Qundef ? 0 : (size_t)NUM2INT(kwvalues[2]);
95
+ const size_t offset = kwvalues[1] == Qundef ? 0 : NUM2SIZET(kwvalues[1]);
96
+ const size_t size = kwvalues[2] == Qundef ? 0 : NUM2SIZET(kwvalues[2]);
95
97
 
96
98
  if (get_double_array(self)->open(filename, mode, offset, size) != 0) {
97
99
  return Qfalse;
@@ -110,7 +112,7 @@ class RbDoubleArray
110
112
 
111
113
  const char* filename = StringValueCStr(_filename);
112
114
  const char* mode = kwvalues[0] == Qundef ? "wb" : StringValueCStr(kwvalues[0]);
113
- const size_t offset = kwvalues[1] == Qundef ? 0 : (size_t)NUM2INT(kwvalues[1]);
115
+ const size_t offset = kwvalues[1] == Qundef ? 0 : NUM2SIZET(kwvalues[1]);
114
116
 
115
117
  if (get_double_array(self)->save(filename, mode, offset) != 0) {
116
118
  return Qfalse;
@@ -118,6 +120,20 @@ class RbDoubleArray
118
120
  return Qtrue;
119
121
  };
120
122
 
123
+ static VALUE _double_array_get_array(VALUE self) {
124
+ const char* arr = (char*)get_double_array(self)->array();
125
+ const size_t sz = get_double_array(self)->total_size();
126
+ return rb_str_new(arr, sz);
127
+ };
128
+
129
+ static VALUE _double_array_set_array(VALUE self, VALUE bytes) {
130
+ const size_t sz = NUM2SIZET(rb_funcall(bytes, rb_intern("size"), 0));
131
+ const size_t total_sz = sz / get_double_array(self)->unit_size();
132
+ char* arr = StringValuePtr(bytes);
133
+ get_double_array(self)->set_array(arr, total_sz);
134
+ return Qnil;
135
+ };
136
+
121
137
  static VALUE _double_array_exact_match_search(int argc, VALUE* argv, VALUE self) {
122
138
  VALUE _key = Qnil;
123
139
  VALUE kwargs = Qnil;
@@ -133,8 +149,8 @@ class RbDoubleArray
133
149
  }
134
150
 
135
151
  const char* key = StringValueCStr(_key);
136
- const size_t length = kwvalues[0] == Qundef ? 0 : (size_t)NUM2INT(kwvalues[0]);
137
- const size_t node_pos = kwvalues[1] == Qundef ? 0 : (size_t)NUM2INT(kwvalues[1]);
152
+ const size_t length = kwvalues[0] == Qundef ? 0 : NUM2SIZET(kwvalues[0]);
153
+ const size_t node_pos = kwvalues[1] == Qundef ? 0 : NUM2SIZET(kwvalues[1]);
138
154
 
139
155
  Darts::DoubleArray::value_type value;
140
156
  get_double_array(self)->exactMatchSearch(key, value, length, node_pos);
@@ -156,9 +172,9 @@ class RbDoubleArray
156
172
  }
157
173
 
158
174
  const char* key = StringValueCStr(_key);
159
- const size_t max_num_results = kwvalues[0] == Qundef ? (size_t)NUM2INT(rb_funcall(_key, rb_intern("size"), 0)) : (size_t)NUM2INT(kwvalues[0]);
160
- const size_t length = kwvalues[1] == Qundef ? 0 : (size_t)NUM2INT(kwvalues[1]);
161
- const size_t node_pos = kwvalues[2] == Qundef ? 0 : (size_t)NUM2INT(kwvalues[2]);
175
+ const size_t max_num_results = kwvalues[0] == Qundef ? NUM2SIZET(rb_funcall(_key, rb_intern("size"), 0)) : NUM2SIZET(kwvalues[0]);
176
+ const size_t length = kwvalues[1] == Qundef ? 0 : NUM2SIZET(kwvalues[1]);
177
+ const size_t node_pos = kwvalues[2] == Qundef ? 0 : NUM2SIZET(kwvalues[2]);
162
178
 
163
179
  Darts::DoubleArray::result_pair_type* results =
164
180
  (Darts::DoubleArray::result_pair_type*)ruby_xmalloc(max_num_results * sizeof(Darts::DoubleArray::result_pair_type));
@@ -191,9 +207,9 @@ class RbDoubleArray
191
207
  rb_get_kwargs(kwargs, kwtable, 2, 1, kwvalues);
192
208
 
193
209
  const char* key = StringValueCStr(_key);
194
- size_t node_pos = (size_t)NUM2INT(kwvalues[0]);
195
- size_t key_pos = (size_t)NUM2INT(kwvalues[1]);
196
- const size_t length = kwvalues[2] == Qundef ? 0 : (size_t)NUM2INT(kwvalues[2]);
210
+ size_t node_pos = NUM2SIZET(kwvalues[0]);
211
+ size_t key_pos = NUM2SIZET(kwvalues[1]);
212
+ const size_t length = kwvalues[2] == Qundef ? 0 : NUM2SIZET(kwvalues[2]);
197
213
 
198
214
  Darts::DoubleArray::value_type value = get_double_array(self)->traverse(key, node_pos, key_pos, length);
199
215
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DartsClone
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  DARTS_CLONE_VERSION = '0.32'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dartsclone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - yoshoku
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-04 00:00:00.000000000 Z
11
+ date: 2020-10-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Darts-clone.rb is a Ruby binding for the Darts-clone.
14
14
  email: