rpatricia 0.09 → 1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Changes CHANGED
@@ -1,3 +1,6 @@
1
+ 1.0 2012/10/05
2
+ - Add Patricia#nodes methods to return all nodes as a Hash
3
+
1
4
  0.09 2012/07/18
2
5
  - fix bounds error leading to "invalid prefix" exceptions
3
6
 
data/README CHANGED
@@ -165,6 +165,13 @@ show_nodes:
165
165
 
166
166
  This method prints all the nodes in the Patricia Trie.
167
167
 
168
+ nodes:
169
+
170
+ pt.nodes
171
+
172
+ This method returns all the nodes and values in the Patricia Trie
173
+ as a Ruby Hash object.
174
+
168
175
  data:
169
176
 
170
177
  node.data
@@ -202,6 +202,30 @@ p_print_nodes (int argc, VALUE *argv, VALUE self)
202
202
  return Qtrue;
203
203
  }
204
204
 
205
+ static VALUE
206
+ p_nodes (VALUE self)
207
+ {
208
+ VALUE buf = rb_str_new(0, 0);
209
+ char *cbuf;
210
+ patricia_tree_t *tree;
211
+ patricia_node_t *node;
212
+ VALUE hash;
213
+
214
+ Data_Get_Struct(self, patricia_tree_t, tree);
215
+
216
+ hash = rb_hash_new();
217
+ if (tree->head) {
218
+ PATRICIA_WALK(tree->head, node) {
219
+ rb_str_resize(buf, PATRICIA_MAXSTRLEN);
220
+ cbuf = RSTRING_PTR(buf);
221
+ prefix_toa2x(node->prefix, cbuf, 1);
222
+ rb_str_set_len(buf, strlen(cbuf));
223
+ rb_hash_aset(hash, buf, (VALUE)node->data);
224
+ } PATRICIA_WALK_END;
225
+ }
226
+ return hash;
227
+ }
228
+
205
229
  static VALUE
206
230
  p_data (VALUE self)
207
231
  {
@@ -385,6 +409,7 @@ Init_rpatricia (void)
385
409
  /* derivatives of climb */
386
410
  rb_define_method(cPatricia, "num_nodes", p_num_nodes, 0);
387
411
  rb_define_method(cPatricia, "show_nodes", p_print_nodes, -1);
412
+ rb_define_method(cPatricia, "nodes", p_nodes, 0);
388
413
 
389
414
  /* destroy tree */
390
415
  rb_define_method(cPatricia, "destroy", p_destroy, 0);
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = %q{rpatricia}
6
- s.version = %q{0.09} # remember to update Changes if this is changed
6
+ s.version = %q{1.0} # remember to update Changes if this is changed
7
7
 
8
8
  s.homepage = "http://www.goto.info.waseda.ac.jp/~tatsuya/rpatricia/"
9
9
 
data/test.rb CHANGED
@@ -60,4 +60,7 @@ my_test(4 == t.num_nodes)
60
60
  puts "test: showing all nodes"
61
61
  t.show_nodes
62
62
 
63
+ puts "test: return all nodes in Hash"
64
+ my_test(t.nodes == {"127.0.0.0/24"=>"", "192.168.1.0/24"=>"", "192.168.2.0/24"=>"", "192.168.3.100/32"=>""})
65
+
63
66
  t.destroy
metadata CHANGED
@@ -1,39 +1,36 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rpatricia
3
- version: !ruby/object:Gem::Version
4
- hash: 25
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 9
9
- version: "0.09"
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Tatsuya Mori
13
9
  - Eric Wong
14
10
  autorequire:
15
11
  bindir: bin
16
12
  cert_chain: []
17
-
18
- date: 2012-07-31 00:00:00 Z
13
+ date: 2012-10-05 00:00:00.000000000 Z
19
14
  dependencies: []
15
+ description: ! 'This is a ruby wrapper of Net::Patricia, which has been developed
16
+ by
20
17
 
21
- description: |-
22
- This is a ruby wrapper of Net::Patricia, which has been developed by
23
18
  Dave Plonka. The original Net::Patricia and its C API are available
19
+
24
20
  from:
21
+
25
22
  http://net.doit.wisc.edu/~plonka/Net-Patricia/
26
-
23
+
24
+
27
25
  Net::Patricia is a module for fast IP address/prefix lookups.
28
- I have modified some interfaces for the Ruby wrapper version.
26
+
27
+ I have modified some interfaces for the Ruby wrapper version.'
29
28
  email: normalperson@yhbt.net
30
29
  executables: []
31
-
32
- extensions:
30
+ extensions:
33
31
  - ext/rpatricia/extconf.rb
34
32
  extra_rdoc_files: []
35
-
36
- files:
33
+ files:
37
34
  - Changes
38
35
  - README
39
36
  - TODO
@@ -47,36 +44,27 @@ files:
47
44
  - test.rb
48
45
  homepage: http://www.goto.info.waseda.ac.jp/~tatsuya/rpatricia/
49
46
  licenses: []
50
-
51
47
  post_install_message:
52
48
  rdoc_options: []
53
-
54
- require_paths:
49
+ require_paths:
55
50
  - lib
56
- required_ruby_version: !ruby/object:Gem::Requirement
51
+ required_ruby_version: !ruby/object:Gem::Requirement
57
52
  none: false
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- hash: 3
62
- segments:
63
- - 0
64
- version: "0"
65
- required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
58
  none: false
67
- requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- hash: 3
71
- segments:
72
- - 0
73
- version: "0"
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
74
63
  requirements: []
75
-
76
64
  rubyforge_project:
77
- rubygems_version: 1.8.24
65
+ rubygems_version: 1.8.21
78
66
  signing_key:
79
67
  specification_version: 3
80
68
  summary: module for fast IP address/prefix lookups
81
69
  test_files: []
82
-
70
+ has_rdoc: