ffi-radix_tree 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/ffi/radix_tree.rb +15 -0
- data/lib/ffi/radix_tree/version.rb +1 -1
- data/vendor/radixtree/ffi_radix_tree.cpp +2 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b481cbe2fe92e746154ef5d7f640eaa360b2ad1
|
4
|
+
data.tar.gz: 2c31d231c98984ea3ac623c673fea32f3d9f49e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1569a95cd03b4dee2136b26175e83a3732572b7aaf30af692169d0831f4748fb103603de25414160b54f0a56b59c5b194e75d8ae819cdf58d3c032a5869a4c16
|
7
|
+
data.tar.gz: bdc72d457259f6fb473f0690974fefbc10fb36ff121cfc6dd75c2ae8de517caf86e27ff7107af7d028244053b2ac514c856e22d296ed06794d634815e4096c6d
|
data/.gitignore
CHANGED
data/lib/ffi/radix_tree.rb
CHANGED
@@ -86,11 +86,20 @@ module FFI
|
|
86
86
|
DESTROY_METHOD = ::FFI::RadixTree.method(:destroy)
|
87
87
|
FREE_METHOD = ::FFI::RadixTree.method(:match_free)
|
88
88
|
|
89
|
+
def self.destroy!(tree)
|
90
|
+
tree.destroy! unless tree.nil?
|
91
|
+
end
|
92
|
+
|
89
93
|
def initialize
|
90
94
|
@ptr = ::FFI::AutoPointer.new(::FFI::RadixTree.create, DESTROY_METHOD)
|
91
95
|
@first_character_present = {}
|
92
96
|
end
|
93
97
|
|
98
|
+
def destroy!
|
99
|
+
::FFI::RadixTree.destroy(@ptr) unless @ptr.nil?
|
100
|
+
@ptr = nil
|
101
|
+
end
|
102
|
+
|
94
103
|
def has_key?(key)
|
95
104
|
::FFI::RadixTree.has_key(@ptr, key)
|
96
105
|
end
|
@@ -111,6 +120,8 @@ module FFI
|
|
111
120
|
bytesize = byte_length.read_int
|
112
121
|
return nil if bytesize <= 0
|
113
122
|
::MessagePack.unpack(byte_pointer.get_bytes(0, bytesize))
|
123
|
+
ensure
|
124
|
+
::FFI::RadixTree.match_free(byte_pointer) unless byte_pointer.nil?
|
114
125
|
end
|
115
126
|
|
116
127
|
def longest_prefix(string)
|
@@ -119,6 +130,8 @@ module FFI
|
|
119
130
|
p_out = ::FFI::AutoPointer.new(p_out, FREE_METHOD) unless p_out.nil?
|
120
131
|
value.force_encoding("UTF-8") unless value.nil?
|
121
132
|
value
|
133
|
+
ensure
|
134
|
+
::FFI::RadixTree.match_free(p_out) unless p_out.nil?
|
122
135
|
end
|
123
136
|
|
124
137
|
def longest_prefix_value(string)
|
@@ -128,6 +141,8 @@ module FFI
|
|
128
141
|
bytesize = byte_length.read_int
|
129
142
|
return nil if bytesize <= 0
|
130
143
|
::MessagePack.unpack(byte_pointer.get_bytes(0, bytesize))
|
144
|
+
ensure
|
145
|
+
::FFI::RadixTree.match_free(byte_pointer) unless byte_pointer.nil?
|
131
146
|
end
|
132
147
|
end
|
133
148
|
end
|
@@ -34,6 +34,7 @@ bool has_key(radix_tree<std::string, std::vector<char>>* map_pointer, const char
|
|
34
34
|
void match_free(const char* match) {
|
35
35
|
if (match != NULL) {
|
36
36
|
delete[] match;
|
37
|
+
match = NULL;
|
37
38
|
}
|
38
39
|
}
|
39
40
|
|
@@ -97,5 +98,6 @@ void insert(radix_tree<std::string, std::vector<char>>* map_pointer, const char*
|
|
97
98
|
|
98
99
|
void destroy(radix_tree<std::string, std::vector<char>>* map_pointer) {
|
99
100
|
delete map_pointer;
|
101
|
+
map_pointer = NULL;
|
100
102
|
}
|
101
103
|
EXTERN_C_END
|
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.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Dewitt
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: msgpack
|
@@ -126,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
126
|
version: '0'
|
127
127
|
requirements: []
|
128
128
|
rubyforge_project:
|
129
|
-
rubygems_version: 2.
|
129
|
+
rubygems_version: 2.5.1
|
130
130
|
signing_key:
|
131
131
|
specification_version: 4
|
132
132
|
summary: radix tree implementation in c++ with FFI bindings
|