ffi-radix_tree 0.5.0 → 0.6.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: 273613cad863a6795457a41a30cac700b0f1a1a0be3e53359ab6dff4c405cc00
4
- data.tar.gz: 3533ae343c7fbf6d4a5cee15ad33f69bd7c63f0df3a1e239d684a9605215268d
3
+ metadata.gz: 63946ad680524b97f53dd06a3bb4514ce3ab4b12a2f2d5a23fef32e36941bfba
4
+ data.tar.gz: 4235440c2f4f348c3d9f9e496ba5dbf1b0c5c4645b674cd04086ce60f57da650
5
5
  SHA512:
6
- metadata.gz: 3b1cfcf6c1121b84d4b0f51f76dff086e76e854ca2de8eb9d4c3d70446566c4524572194f5490d7c8625e60e61701ce02383d168d47462732f4aee423685789d
7
- data.tar.gz: f1c75e06b8af34d66d463c3b2702854ce711a08ae33eb4e6d69d58d72954e01d2e7777b80bcdd1f95d6bdf40fedafb4f11f7fbea1d39df1af0ee25354f7fc2a2
6
+ metadata.gz: 7ac02fdf65f154c8c3746a565b2b6d3afe738643b9227f82313ddc7bc12cfce6f2f617ac535a876fa2b6da60588fe8564b9d24d86212f71f568fcf2d08ce9ff3
7
+ data.tar.gz: ee16b0514b5a1efef08d3a95c7646e78e9ab44d2f110a3b928aa5335964f63a86b1fb064847c9ba9ac417c4c951bc72259e8039a07556b8c0739806affe9bd37
@@ -1,5 +1,5 @@
1
1
  module FFI
2
2
  module RadixTree
3
- VERSION = "0.5.0"
3
+ VERSION = "0.6.0"
4
4
  end
5
5
  end
@@ -84,6 +84,7 @@ module FFI
84
84
  attach_function :greedy_match, [:pointer, :string, :pointer, :pointer], :int
85
85
  attach_function :greedy_substring_match, [:pointer, :string, :pointer, :pointer], :int
86
86
  attach_function :match_free, [:pointer], :void
87
+ attach_function :match_sizes_free, [:pointer], :void
87
88
  attach_function :multi_match_free, [:pointer, :int], :void
88
89
  attach_function :has_key, [:pointer, :string], :bool
89
90
 
@@ -97,6 +98,8 @@ module FFI
97
98
  ::FFI::RadixTree.has_key(@ptr, key)
98
99
  end
99
100
 
101
+ alias_method :key?, :has_key?
102
+
100
103
  def push(key, value)
101
104
  push_response = nil
102
105
  @first_character_present[key[0]] = true
@@ -207,8 +210,8 @@ module FFI
207
210
  ::FFI::MemoryPointer.new(:pointer) do |match_sizes_array|
208
211
  array_size = ::FFI::RadixTree.greedy_match(@ptr, string, match_array, match_sizes_array)
209
212
  if array_size > 0
210
- array_sizes_pointer = match_sizes_array.read_pointer
211
- match_sizes = array_sizes_pointer.get_array_of_int(0, array_size)
213
+ match_sizes_pointer = match_sizes_array.read_pointer
214
+ match_sizes = match_sizes_pointer.get_array_of_int(0, array_size)
212
215
  array_pointer = match_array.read_pointer
213
216
  char_arrays = array_pointer.get_array_of_pointer(0, array_size)
214
217
  char_arrays.each_with_index do |ptr, index|
@@ -221,7 +224,7 @@ module FFI
221
224
  get_response
222
225
  ensure
223
226
  ::FFI::RadixTree.multi_match_free(array_pointer, array_size) if array_pointer
224
- ::FFI::RadixTree.match_free(match_sizes_pointer) if match_sizes_pointer
227
+ ::FFI::RadixTree.match_sizes_free(match_sizes_pointer) if match_sizes_pointer
225
228
  end
226
229
 
227
230
  def greedy_substring_match(string)
@@ -234,8 +237,8 @@ module FFI
234
237
  ::FFI::MemoryPointer.new(:pointer) do |match_sizes_array|
235
238
  array_size = ::FFI::RadixTree.greedy_substring_match(@ptr, string, match_array, match_sizes_array)
236
239
  if array_size > 0
237
- array_sizes_pointer = match_sizes_array.read_pointer
238
- match_sizes = array_sizes_pointer.get_array_of_int(0, array_size)
240
+ match_sizes_pointer = match_sizes_array.read_pointer
241
+ match_sizes = match_sizes_pointer.get_array_of_int(0, array_size)
239
242
  array_pointer = match_array.read_pointer
240
243
  char_arrays = array_pointer.get_array_of_pointer(0, array_size)
241
244
  char_arrays.each_with_index do |ptr, index|
@@ -248,7 +251,7 @@ module FFI
248
251
  get_response
249
252
  ensure
250
253
  ::FFI::RadixTree.multi_match_free(array_pointer, array_size) if array_pointer
251
- ::FFI::RadixTree.match_free(match_sizes_pointer) if match_sizes_pointer
254
+ ::FFI::RadixTree.match_sizes_free(match_sizes_pointer) if match_sizes_pointer
252
255
  end
253
256
  end
254
257
  end
@@ -32,20 +32,19 @@ bool has_key(radix_tree<std::string, std::vector<char>>* map_pointer, const char
32
32
  }
33
33
 
34
34
  void match_free(const char* match) {
35
- if (match != NULL) {
36
- delete[] match;
37
- match = NULL;
38
- }
35
+ delete[] match;
36
+ }
37
+
38
+ void match_sizes_free(const int* match_sizes) {
39
+ delete[] match_sizes;
39
40
  }
40
41
 
41
42
  void multi_match_free(const char** match, int length) {
42
43
  if (match != NULL) {
43
44
  for (int i=0; i<length; ++i) {
44
45
  delete[] match[i];
45
- match[i] = NULL;
46
46
  }
47
47
  delete[] match;
48
- match = NULL;
49
48
  }
50
49
  }
51
50
 
@@ -110,12 +109,12 @@ const char* longest_prefix_value(radix_tree<std::string, std::vector<char>>* map
110
109
  return NULL;
111
110
  }
112
111
 
113
- unsigned char* fetch(radix_tree<std::string, std::vector<char>>* map_pointer, const char* key, int* read_size) {
112
+ char* fetch(radix_tree<std::string, std::vector<char>>* map_pointer, const char* key, int* read_size) {
114
113
  auto iter = map_pointer->find(std::string(key));
115
114
  long counter = 0;
116
115
 
117
116
  if (iter != map_pointer->end()) {
118
- unsigned char *return_val = new unsigned char[iter->second.size()]{0};
117
+ char *return_val = new char[iter->second.size()]{0};
119
118
  for( auto& val : iter->second ) {
120
119
  return_val[counter] = val;
121
120
  counter++;
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-radix_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Dewitt
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-03 00:00:00.000000000 Z
11
+ date: 2021-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -152,7 +152,7 @@ licenses:
152
152
  - MIT
153
153
  metadata:
154
154
  allowed_push_host: https://rubygems.org
155
- post_install_message:
155
+ post_install_message:
156
156
  rdoc_options: []
157
157
  require_paths:
158
158
  - lib
@@ -168,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
168
  version: '0'
169
169
  requirements: []
170
170
  rubygems_version: 3.0.3
171
- signing_key:
171
+ signing_key:
172
172
  specification_version: 4
173
173
  summary: radix tree implementation in c++ with FFI bindings
174
174
  test_files: []