ffi-radix_tree 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ffi/radix_tree.rb +5 -0
- data/lib/ffi/radix_tree/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 244a7a454320674c40f5adb8cb897980b9d73286
|
4
|
+
data.tar.gz: 28840c6a4d0678bfafce07badeab64f428090bf6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72340475d6bf28b58071b96534a0f23f44ed912240fd15ca2ed87917e7a128fb897903143cadf3567fd553849b6cade64c743705eb930d22c01e612e7e0b8c3d
|
7
|
+
data.tar.gz: 905d9ef2f2732aaf5a1e1d2c08a4dd51fa4c604b87980fe515dbc0928c06ddbbb87829626777595889ccdaaf1092ac2cac6469e7bc025cfb7a5c8859674b24f0
|
data/lib/ffi/radix_tree.rb
CHANGED
@@ -88,6 +88,7 @@ module FFI
|
|
88
88
|
|
89
89
|
def initialize
|
90
90
|
@ptr = ::FFI::AutoPointer.new(::FFI::RadixTree.create, DESTROY_METHOD)
|
91
|
+
@first_character_present = {}
|
91
92
|
end
|
92
93
|
|
93
94
|
def has_key?(key)
|
@@ -95,6 +96,7 @@ module FFI
|
|
95
96
|
end
|
96
97
|
|
97
98
|
def push(key, value)
|
99
|
+
@first_character_present[key[0]] = true
|
98
100
|
storage_data = ::MessagePack.pack(value)
|
99
101
|
bytesize = storage_data.bytesize
|
100
102
|
memory_buffer = ::FFI::MemoryPointer.new(:char, bytesize, true)
|
@@ -103,6 +105,7 @@ module FFI
|
|
103
105
|
end
|
104
106
|
|
105
107
|
def get(key)
|
108
|
+
return nil unless @first_character_present[key[0]]
|
106
109
|
byte_length = ::FFI::MemoryPointer.new(:int)
|
107
110
|
byte_pointer = ::FFI::AutoPointer.new(::FFI::RadixTree.fetch(@ptr, key, byte_length), FREE_METHOD)
|
108
111
|
bytesize = byte_length.read_int
|
@@ -111,6 +114,7 @@ module FFI
|
|
111
114
|
end
|
112
115
|
|
113
116
|
def longest_prefix(string)
|
117
|
+
return nil unless @first_character_present[string[0]]
|
114
118
|
value, p_out = ::FFI::RadixTree.longest_prefix(@ptr, string)
|
115
119
|
p_out = ::FFI::AutoPointer.new(p_out, FREE_METHOD) unless p_out.nil?
|
116
120
|
value.force_encoding("UTF-8") unless value.nil?
|
@@ -118,6 +122,7 @@ module FFI
|
|
118
122
|
end
|
119
123
|
|
120
124
|
def longest_prefix_value(string)
|
125
|
+
return nil unless @first_character_present[string[0]]
|
121
126
|
byte_length = ::FFI::MemoryPointer.new(:int)
|
122
127
|
byte_pointer = ::FFI::AutoPointer.new(::FFI::RadixTree.longest_prefix_value(@ptr, string, byte_length), FREE_METHOD)
|
123
128
|
bytesize = byte_length.read_int
|
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.4
|
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-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: msgpack
|