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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe301b0f98349bbce7eb1dd7d0f6782d6c5bf510
4
- data.tar.gz: 7073662f176c8424ac361b9cd5bf70c9ec4238d1
3
+ metadata.gz: 244a7a454320674c40f5adb8cb897980b9d73286
4
+ data.tar.gz: 28840c6a4d0678bfafce07badeab64f428090bf6
5
5
  SHA512:
6
- metadata.gz: b57a47c00fd1b9489a09d3f5928151190794c03023ff6aee0f5b6de54d24314a4d4767e03c659f1146f03057c248683060abed0431b35da5d7a38515036339b8
7
- data.tar.gz: 85daa771d42c681f7d38b9e4b761992dbb7b122e47b70aedd99ec6db8378bb4ebf1d06ab448c369ad5da6b80dd44713ef727eb7cce06232dbc47e0dadc4d139c
6
+ metadata.gz: 72340475d6bf28b58071b96534a0f23f44ed912240fd15ca2ed87917e7a128fb897903143cadf3567fd553849b6cade64c743705eb930d22c01e612e7e0b8c3d
7
+ data.tar.gz: 905d9ef2f2732aaf5a1e1d2c08a4dd51fa4c604b87980fe515dbc0928c06ddbbb87829626777595889ccdaaf1092ac2cac6469e7bc025cfb7a5c8859674b24f0
@@ -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
@@ -1,5 +1,5 @@
1
1
  module FFI
2
2
  module RadixTree
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
  end
5
5
  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.3
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-09 00:00:00.000000000 Z
11
+ date: 2017-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack