ffi-radix_tree 0.1.6 → 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
- SHA256:
3
- metadata.gz: 24b341505b1ae9d77943d26730537193ce58cabe2877add54663f86436e7c0ee
4
- data.tar.gz: 37d2b07791ed42c53e3ccad80e32fb3522bda0fd65d7a8a917a0576b7b6ced71
2
+ SHA1:
3
+ metadata.gz: c2547ed89d9cbedb9bd340a86785aa16f0becd3c
4
+ data.tar.gz: 737b4483c593146c8c9fef84330f9ed5eac149ee
5
5
  SHA512:
6
- metadata.gz: 5244fc5c7d0828e4cc4907575dbca6b65265f8b35b02127d8bfb709dd057cadcd34a7ed5574d8ed23efe58b6b54f07e15b53a348f21413292f08a837579dcea3
7
- data.tar.gz: 3d19a13ba263c5a147fa61be948db117adbf51582cfd3d9a368b27bc1f356ec34d62e37ea9cd08e54c7936d088ea8e448dbdd1086aacf9f525f63ec636116f11
6
+ metadata.gz: 79474879d50035f089b2a04b60db2dee547e9aabf4aeffa43c33b430156bac7004e55da050e35bb71cda97eede7bcda077c9ca4a53dbc66809d040a06c04d277
7
+ data.tar.gz: becb72bae362661101c75aed79d53c42f9d698c19116593b0180971026ba8e59eebcb712d8c65ea7e4e5ffbd71a9de6ef6dcf46b2a22141cc2e64288fdafddb9
data/Rakefile CHANGED
@@ -9,11 +9,12 @@ namespace :radixtree do
9
9
  end
10
10
  end
11
11
 
12
- Rake::TestTask.new(:test) do |t|
13
- t.libs << "test"
12
+ Rake::TestTask.new(:spec) do |t|
13
+ t.libs << "spec"
14
14
  t.libs << "lib"
15
- t.test_files = FileList["test/**/*_test.rb"]
15
+ t.pattern = "spec/**/*_spec.rb"
16
+ t.verbose = true
16
17
  end
17
- Rake::Task[:test].prerequisites << "radixtree:compile"
18
+ Rake::Task[:spec].prerequisites << "radixtree:compile"
18
19
 
19
- task :default => :test
20
+ task :default => :spec
@@ -36,5 +36,7 @@ Gem::Specification.new do |spec|
36
36
 
37
37
  spec.add_development_dependency "bundler", "~> 1.15"
38
38
  spec.add_development_dependency "rake", "~> 10.0"
39
+ spec.add_development_dependency "mocha"
40
+ spec.add_development_dependency "pry"
39
41
  spec.add_development_dependency "minitest", "~> 5.0"
40
42
  end
@@ -74,7 +74,7 @@ module FFI
74
74
 
75
75
  attach_function :create, [], :pointer
76
76
  attach_function :destroy, [:pointer], :void
77
- attach_function :erase, [:string], :void
77
+ attach_function :erase, [:pointer, :string], :void
78
78
  attach_function :fetch, [:pointer, :string, :pointer], :pointer
79
79
  attach_function :insert, [:pointer, :string, :pointer, :size_t], :void
80
80
  attach_function :longest_prefix, [:pointer, :string], :string
@@ -102,43 +102,56 @@ module FFI
102
102
  end
103
103
 
104
104
  def push(key, value)
105
+ push_response = nil
105
106
  @first_character_present[key[0]] = true
106
107
  storage_data = ::MessagePack.pack(value)
107
108
  bytesize = storage_data.bytesize
108
- memory_buffer = ::FFI::MemoryPointer.new(:char, bytesize, true)
109
- memory_buffer.put_bytes(0, storage_data)
110
- ::FFI::RadixTree.insert(@ptr, key, memory_buffer, bytesize)
109
+
110
+ ::FFI::MemoryPointer.new(:char, bytesize, true) do |memory_buffer|
111
+ memory_buffer.put_bytes(0, storage_data)
112
+ push_response = ::FFI::RadixTree.insert(@ptr, key, memory_buffer, bytesize)
113
+ end
114
+
115
+ push_response
111
116
  end
112
117
 
113
118
  def get(key)
114
119
  return nil unless @first_character_present[key[0]]
115
- byte_length = ::FFI::MemoryPointer.new(:int)
116
- byte_pointer = ::FFI::RadixTree.fetch(@ptr, key, byte_length)
117
- bytesize = byte_length.read_int
118
- return nil if bytesize <= 0
119
- ::MessagePack.unpack(byte_pointer.get_bytes(0, bytesize))
120
+ byte_pointer = get_response = nil
121
+
122
+ ::FFI::MemoryPointer.new(:int) do |byte_length|
123
+ byte_pointer = ::FFI::RadixTree.fetch(@ptr, key, byte_length)
124
+ bytesize = byte_length.read_int
125
+ get_response = ::MessagePack.unpack(byte_pointer.get_bytes(0, bytesize)) if bytesize && bytesize > 0
126
+ end
127
+
128
+ get_response
120
129
  ensure
121
- ::FFI::RadixTree.match_free(byte_pointer) unless byte_pointer.nil?
130
+ ::FFI::RadixTree.match_free(byte_pointer) if byte_pointer
122
131
  end
123
132
 
124
133
  def longest_prefix(string)
125
134
  return nil unless @first_character_present[string[0]]
126
135
  value, p_out = ::FFI::RadixTree.longest_prefix(@ptr, string)
127
- value.force_encoding("UTF-8") unless value.nil?
136
+ value.force_encoding("UTF-8") if value
128
137
  value
129
138
  ensure
130
- ::FFI::RadixTree.match_free(p_out) unless p_out.nil?
139
+ ::FFI::RadixTree.match_free(p_out) if p_out
131
140
  end
132
141
 
133
142
  def longest_prefix_value(string)
134
143
  return nil unless @first_character_present[string[0]]
135
- byte_length = ::FFI::MemoryPointer.new(:int)
136
- byte_pointer = ::FFI::RadixTree.longest_prefix_value(@ptr, string, byte_length)
137
- bytesize = byte_length.read_int
138
- return nil if bytesize <= 0
139
- ::MessagePack.unpack(byte_pointer.get_bytes(0, bytesize))
144
+ byte_pointer = get_response = nil
145
+
146
+ ::FFI::MemoryPointer.new(:int) do |byte_length|
147
+ byte_pointer = ::FFI::RadixTree.longest_prefix_value(@ptr, string, byte_length)
148
+ bytesize = byte_length.read_int
149
+ get_response = ::MessagePack.unpack(byte_pointer.get_bytes(0, bytesize)) if bytesize && bytesize > 0
150
+ end
151
+
152
+ get_response
140
153
  ensure
141
- ::FFI::RadixTree.match_free(byte_pointer) unless byte_pointer.nil?
154
+ ::FFI::RadixTree.match_free(byte_pointer) if byte_pointer
142
155
  end
143
156
  end
144
157
  end
@@ -1,5 +1,5 @@
1
1
  module FFI
2
2
  module RadixTree
3
- VERSION = "0.1.6"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,80 +1,108 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-radix_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.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: 2017-10-19 00:00:00.000000000 Z
11
+ date: 2018-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ name: msgpack
14
15
  requirement: !ruby/object:Gem::Requirement
15
16
  requirements:
16
17
  - - ">="
17
18
  - !ruby/object:Gem::Version
18
19
  version: '0'
19
- name: msgpack
20
- prerelease: false
21
20
  type: :runtime
21
+ prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
+ name: ffi
28
29
  requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
31
  - - ">="
31
32
  - !ruby/object:Gem::Version
32
33
  version: '0'
33
- name: ffi
34
- prerelease: false
35
34
  type: :runtime
35
+ prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
+ name: bundler
42
43
  requirement: !ruby/object:Gem::Requirement
43
44
  requirements:
44
45
  - - "~>"
45
46
  - !ruby/object:Gem::Version
46
47
  version: '1.15'
47
- name: bundler
48
- prerelease: false
49
48
  type: :development
49
+ prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.15'
55
55
  - !ruby/object:Gem::Dependency
56
+ name: rake
56
57
  requirement: !ruby/object:Gem::Requirement
57
58
  requirements:
58
59
  - - "~>"
59
60
  - !ruby/object:Gem::Version
60
61
  version: '10.0'
61
- name: rake
62
- prerelease: false
63
62
  type: :development
63
+ prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '10.0'
69
69
  - !ruby/object:Gem::Dependency
70
+ name: mocha
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: minitest
70
99
  requirement: !ruby/object:Gem::Requirement
71
100
  requirements:
72
101
  - - "~>"
73
102
  - !ruby/object:Gem::Version
74
103
  version: '5.0'
75
- name: minitest
76
- prerelease: false
77
104
  type: :development
105
+ prerelease: false
78
106
  version_requirements: !ruby/object:Gem::Requirement
79
107
  requirements:
80
108
  - - "~>"
@@ -110,7 +138,7 @@ licenses:
110
138
  - MIT
111
139
  metadata:
112
140
  allowed_push_host: https://rubygems.org
113
- post_install_message:
141
+ post_install_message:
114
142
  rdoc_options: []
115
143
  require_paths:
116
144
  - lib
@@ -125,9 +153,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
153
  - !ruby/object:Gem::Version
126
154
  version: '0'
127
155
  requirements: []
128
- rubyforge_project:
129
- rubygems_version: 2.6.11
130
- signing_key:
156
+ rubyforge_project:
157
+ rubygems_version: 2.6.13
158
+ signing_key:
131
159
  specification_version: 4
132
160
  summary: radix tree implementation in c++ with FFI bindings
133
161
  test_files: []