rpatricia.git  about / heads / tags
see http://www.goto.info.waseda.ac.jp/~tatsuya/rpatricia/
blob 459f03d7297faeedc8bd6fb0ce43f70deca29150 5608 bytes (raw)
$ git show HEAD:README	# shows this blob on the CLI

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
 
README for Ruby wrapper of Net::Patricia
---------------------------------------

rPatricia - A ruby wrapper of Net::Patricia

DESCRIPTION
-----------

  This is a ruby wrapper of Net::Patricia, which has been developed by 
  Dave Plonka. The original Net::Patricia and its C API are available
  from:
  http://net.doit.wisc.edu/~plonka/Net-Patricia/

  Net::Patricia is a module for fast IP address/prefix lookups.
  I have modified some interfaces for the Ruby wrapper version. 

NO WARANTY
----------    
    THE PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
    WITHOUT ANY WARRANTY. IT IS PROVIDED "AS IS" WITHOUT WARRANTY OF
    ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED
    TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
    PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND
    PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE
    DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR
    OR CORRECTION. 

INSTALLATION
------------

   This package extracts, builds, installs in the usual fashion, i.e.:

      $ tar xvfz rpatricia.tar.gz
      $ cd rpatricia
      $ ruby extconf.rb
      $ make
      $ ruby test.rb
      # make install

SYNOPSIS
--------

  require 'rpatricia'
  pt = Patricia.new
  pt.add("192.168.1.0/24")
  pt.add("127.0.0.0/8", "user_data")
  node = pt.search_best("127.0.0.1")
  puts node.data
  puts node.prefix
  puts node.network
  puts node.prefixlen
  pt.remove("127.0.0.0/8")
  puts pt.num_nodes
  pt.show_nodes
  pt.clear

METHODS
-------
new:

      pt = Patricia.new

    This is the class' constructor - it returns a Patricia object for
    handling IPv4 addresses.  To handle IPv6 addresses (only),
    Patricia.new may be called with an additional argument:

      pt = Patricia.new(:AF_INET6)

    The Patricia object will be destroyed automatically when there are
    no longer any references to it.

add:
      pt.add(key_string[,user_data])

    The first argument, key_string, is a network or subnet
    specification in canonical form, e.g. ``10.0.0.0/8'', where the
    number after the slash represents the number of bits in the
    netmask. If no mask width is specified, the longest possible mask
    is assumed, i.e. 32 bits for AF_INET addresses and 128 bits for
    AF_INET6 addresses.

    The second argument, user_data, is optional. If supplied, it
    should be a STRING object specifying the user data that will be 
    stored in the Patricia Trie node. Subsequently, this value will
    be returned by the match methods described below to indicate a 
    successful search. 

    If no second argument is passed, the key_string will be stored as
    the user data and therfore will likewise be returned by the match
    functions.

    On success, this method returns the object of the Patricia Trie 
    node.

family:

    Returns either :AF_INET or :AF_INET6 symbol depending on how the
    object was initialized.  A Patricia object may only handle IPv4 or
    IPv6 addresses.

add_node:    An alias of add.

search_best:

      pt.search_best(key_string);

    This method searches the Patricia Trie to find a matching node,
    according to normal subnetting rules for the address and mask
    specified.

    The key_string argument is a network or subnet specification in
    canonical form, e.g. ``10.0.0.0/8'', where the number after the
    slash represents the number of bits in the netmask. If no mask
    width value is specified, the longest mask is assumed, i.e. 32
    bits for AF_INET addresses and 128 bits for AF_INET6 addresses.

    If a matching node is found in the Patricia Trie, this method
    returns the object of the node. This method returns nil on
    failure.

match_best:    An alias of search_best.

search_exact:

      pt.search_exact(key_string);

    This method searches the Patricia Trie to find a matching
    node. Its semantics are exactly the same as those described for
    search_best except that the key must match a node exactly. I.e.,
    it is not sufficient that the address and mask specified merely
    falls within the subnet specified by a particular node.

match_exact:	An alias of search_exact.

include?:

      pt.include?(key_string);

    This method behaves like match_best, but returns true on success
    and false on failure.  This method is more efficient than match_best
    as it does not allocate a new object.

remove:

      pt.remove(key_string);

    This method removes the node which exactly matches the the address
    and mask specified from the Patricia Trie.

    If the matching node is found in the Patricia Trie, it is removed,
    and this method returns the true. This method returns false on
    failure. 

remove_node:	 An alias of remove

num_nodes:
       
       pt.num_nodes

     This method returns the number of nodes in the Patricia Trie.

show_nodes:

       pt.print_nodes

     This method prints all the nodes in the Patricia Trie.

nodes:

       pt.nodes

     This method returns all the nodes and values in the Patricia Trie
     as a Ruby Hash object.

data:

       node.data
   
     This method returns the user data of the Patricia Trie node.

network:

       node.network
   
     This method returns the network of the Patricia Trie node.

prefix:

       node.prefix
   
     This method returns the prefix of the Patricia Trie node.

prefixlen:

       node.prefixlen
   
     This method returns the prefix length of the Patricia Trie 
     node.

AUTHORS
-------
Tatsuya Mori <mori.tatsuya@gmail.com>
Eric Wong <normalperson@yhbt.net>

git clone https://yhbt.net/rpatricia.git