Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

RE: Sorting a list of IP addresses (aka Why I hate Big O)

by DrManhattan (Chaplain)
on Aug 03, 2000 at 16:25 UTC ( #25958=note: print w/replies, xml ) Need Help??


in reply to Sorting a list of IP addresses (aka Why I hate Big O)

Read further down in the Guttman/Rosler paper to where they discuss the "packed-default" sort:

@out = map substr($_, 4) => sort map pack('C4' => /(\d+)\.(\d+)\.(\d+)\.(\d+)/) . $_ => @in;

The idea is to pack the entire list once before sorting it then get each address back out with a substr afterwards. Using this technique, you only make N packs and N substrs, instead of N*log(N) packs. It also has the advantage of using sort without calling a subroutine for each comparison which is a huge speedup.

-Matt

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://25958]
help
Chatterbox?
[Discipulus]: ridiculous! i'm leading the montly best section. oh tempora oh mores..
[Corion]: :-D
[Eily]: congrats Discipulus :)
[Eily]: (somehow I just typed "cong" and chrome proposed to complete the message :D )

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2017-04-26 11:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (473 votes). Check out past polls.