Ruby replacement for net::patricia needed

I’m looking for the ruby equivalent of the perl Net::Patricia module
which uses the Patricia Trie algorithm for storing objects in
association with a ip address/mask combinations. For example,

p = Patricia.new()
p.add_address(‘127.0.0.0/8’, obj) # stores object obj
o = p.match(‘127.0.0.1’) # returns object obj

Is there anything similar already in existence for ruby? Is it possible
to adapt the acl modules?

I’m trying to avoid re-inventing the wheel.

Jeff.

jm wrote:

I’m looking for the ruby equivalent of the perl Net::Patricia module
which uses the Patricia Trie algorithm for storing objects in
association with a ip address/mask combinations. For example,

p = Patricia.new()
p.add_address(‘127.0.0.0/8’, obj) # stores object obj
o = p.match(‘127.0.0.1’) # returns object obj

Is there anything similar already in existence for ruby? Is it possible
to adapt the acl modules?

I’m trying to avoid re-inventing the wheel.

Jeff.

Is there an overall Trie object in Ruby at all? I would be interested
in one if it exists. If it doesn’t maybe that’s something important we
are missing. I’m done with finals in a week or so, maybe i’ll throw
something together after that.
Charles Comstock

I’m looking for the ruby equivalent of the perl Net::Patricia module
which uses the Patricia Trie algorithm for storing objects in
association with a ip address/mask combinations. For example,

I’m not familiar with this package but…

p = Patricia.new()
p.add_address(‘127.0.0.0/8’, obj) # stores object obj
o = p.match(‘127.0.0.1’) # returns object obj

Tuplespaces may help, though you’ll need to create some Netmask
class with an === operator so it will compare the addresses against
the mask (to do the matching) the way you want. This is part of Rinda
which is part of ruby out of the box.

    [...]

Jeff.

    Hugh
···

On Fri, 7 May 2004, jm wrote:

In Message-Id: AF51BBF4-9FE9-11D8-9DC6-000A95D0C980@transact.com.au
jm jm@transact.com.au writes:

p = Patricia.new()
p.add_address(‘127.0.0.0/8’, obj) # stores object obj
o = p.match(‘127.0.0.1’) # returns object obj

Is there anything similar already in existence for ruby? Is it
possible to adapt the acl modules?

I don’t know whether patricia trie itself is essential or not, but
ipaddr.rb, bundled with the current Ruby distribution, may help you.

require "ipaddr"

net = IPAddr.new("127.0.0.0/8")
net.include?(IPAddr.new("127.0.0.1")) #=> true
···


kjana@dm4lab.to May 7, 2004
A man is known by the company he keeps.

It would be much appreciated. I shouldn’t be playing with ruby at the
moment either I’ve couple of assignments and exams to look forward to
in the next month (along with full time work).

Jeff.

···

On 07/05/2004, at 4:03 PM, Charles Comstock wrote:

Is there an overall Trie object in Ruby at all? I would be interested
in one if it exists. If it doesn’t maybe that’s something important
we are missing. I’m done with finals in a week or so, maybe i’ll
throw something together after that.
Charles Comstock

This combined with the suggestion made by hgs@dmu.ac.uk to use
truplespaces may provide a short term solution. The only problem I
have with truplespaces is the number of match operations that may be
needed. I checked the authors web pages (which is in japanese) from
reading between the lines I don’t think he mentions what algorithm he
uses.
Looks like I’ll have to read the source.

Take a look at some of the following for info on patricia tries if your
curious,

“Optimized IP to ISO3166 Country Code Mapping in C#” which uses tries
http://www.codeproject.com/csharp/iptocountry.asp

This paper discusses various algorithms (it contains some typos)
http://herodes.redes.upv.es/rap/Routers%20Altas%20Prestaciones/
ip_report.pdf

Citation info for original paper,
http://theory.lcs.mit.edu/~jacm/Authors/morrisondonaldr.html

Jeff.

···

On 07/05/2004, at 9:45 PM, YANAGAWA Kazuhisa wrote:

In Message-Id: AF51BBF4-9FE9-11D8-9DC6-000A95D0C980@transact.com.au
jm jm@transact.com.au writes:

p = Patricia.new()
p.add_address(‘127.0.0.0/8’, obj) # stores object obj
o = p.match(‘127.0.0.1’) # returns object obj

Is there anything similar already in existence for ruby? Is it
possible to adapt the acl modules?

I don’t know whether patricia trie itself is essential or not, but
ipaddr.rb, bundled with the current Ruby distribution, may help you.

require "ipaddr"

net = IPAddr.new("127.0.0.0/8")
net.include?(IPAddr.new("127.0.0.1")) #=> true


kjana@dm4lab.to May 7, 2004
A man is known by the company he keeps.