Sort IP List
Bernd.Niggemann at uni-wh.de
Sat Jun 30 04:37:04 EDT 2018
if you replace ip2dec with the same functionality as Hermann's (HH) function with
private function ip2dec2 x
set the itemdel to "."
return (item 4 of x) + (item 3 of x * 256) + (item 2 of x * 65536) + (item 1 of x * 16777216)
then the special sort via function is faster than sorting the 4 items of the IPlist.
Note "private function" saves about 10 percent, overall Hermann's modified script saves about 20 percent compared to Bob's sort by item solution which was fastest up to now.
Tested 100.000 random IP addresses.
hh via use-livecode<https://firstname.lastname@example.org&q=from:%22hh+via+use%5C-livecode%22> Fri, 29 Jun 2018 16:43:38 -0700<https://email@example.com&q=date:20180629> wrote:
Your IP addresses [0-255].[0-255].[0-255].[0-255]
are the hex IP numbers converted to base 256.
So you may try the following sorting function that
converts the IPs from base 256 to base 10 (decimal).
function ip2dec x
set itemdel to "."
repeat with i=0 to 3
add (item 4-i of x)*256^i to y
put fld "ips" into s
sort s numeric by ip2dec(each) # <----
put s into fld "out"
More information about the Use-livecode