Thanks for your informative reply.

If I had know that mod::Net::IPTrie or mod::Tree::Trie existed I would have use them, unfortunately I did not know they existed and did not know the terminology to search for them on CPAN, and I thought it would take to long to implement something myself.

Instead I wrote some code using string representations of the binary bits in a database using DBIx::Class.

My DBIC table defintion looks like this:

__PACKAGE__->table('tblSubNet'); __PACKAGE__->add_columns( 'id' => { data_type=>'int', is_auto_increment=>1 + }, 'ip' => { data_type=>'varchar', size=>15 + }, 'mask' => { data_type=>'int' + }, 'name' => { data_type=>'varchar', size=>255, is_nullable=>1 + }, 'start' => { data_type=>'int' + }, # the IP address as A 32 bit number 'bitpattern' => { data_type=>'varchar', size=>32 + }, ); __PACKAGE__->set_primary_key('id'); __PACKAGE__->add_unique_constraint(['bitpattern']);

Once I have populated the table of subnets, I then search it like this:

my $order_by_size_rs = $all_subnets_rs->search({'source'=>$source},{'o +rder_by'=>{'-asc','mask'}}); while( my $network = $order_by_size_rs->next ) { my $overlaping_nets_rs = $net_rs->search({ 'mask' => { '>', $network->mask() }, 'bitpattern' => { 'like', $network->bitpattern().'%' }, }, { 'order_by'=>{'-asc',['mask','start']} }); if( $overlaping_nets_rs->count ) { printf "Subnet %s/%d (%s) has %d overlaps:\n", $network->ip, $network->mask, $network->name, $overlaping_nets_rs->count; ... # Code to add the overlaps to the report. } }

Using this algorithm I was able to search through the 50_000 subnets searching for overlaps in about 10 minutes. (On a 3GHz Linux box).


In reply to Re^2: Algorithom to find overlaping subnets (Internet IPv4) by chrestomanci
in thread Algorithom to find overlaping subnets (Internet IPv4) by chrestomanci

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.