Sort IP List

Mike Bonner bonnmike at
Fri Jun 29 12:35:29 EDT 2018

## was writing this when your response showed up..
Just did some tests.  For reasonable size lists of IP numbers, your method
is clearly faster. As lines increase the disparity shrinks (due to 4
processings of the same lines rather than 1) until around 35000 lines at
which point positions reverse and the disparity grows in favor of the
function(each) method.

After just a bit more testing, the fastest method (for anything over 20000
lines) is to run through the whole list first converting it to numeric and
then do a single simple sort, but that leaves you with a straight list of
numbers that would then have to be re-divided into triads, so the post
processing needed kills the whole idea.

As for your response,
Yes  the function is called by sort for each line and returns the numbers
to use to give that line its sort value.  It isn't as fast as I had hoped
most likely because it has to call a function for each line in the list.
With the first method I posted, on my machine, the crossover point is right
around 35000 lines (at least on my system, at 35000 lines it takes 475
millisec to 612 millisec vs the 4xsort)   At 200,000 lines the disparity
grows to over 3 seconds difference, but i'm unsure what max length list
might be reasonably expected.  The 4 sort method is by far the simplest to
code and is plenty fast for list under 100000.
The nicest part of your method is that if processing a huge list, its easy
to give visual feedback between each sort if need be.  But again, all this
is likely moot unless the ip list is huge.

On Fri, Jun 29, 2018 at 9:37 AM Mike Bonner <bonnmike at> wrote:

> I don't know what speed differences there might be, but another option is
> something like this..
> function ipfunc pIp
>    set the itemdel to "."
>    set the numberformat to "###" -- force length of each chunk to 3
> -- append the numbers together sans "." with padded 0's using numberformat
>    repeat for each item tItem in pIp
>          put tItem +0 after tIp -- do the add to force the numberformat to
> work
>    end repeat
>    return tIp
> end ipfunc
> And then use it like so..
> sort lines of myIpList ascending numeric by ipfunc(each)
> On Fri, Jun 29, 2018 at 9:14 AM Bob Sneidar via use-livecode <
> use-livecode at> wrote:
>> Hi all.
>> I somehow got on to how to sort IP addresses, seeing they are not real
>> numbers, and read in the dictionary that the sort command is a "stable
>> sort". This occured to me:
>> function sortIPList pIPList
>>    set the itemdelimiter to "."
>>    sort lines of pIPList numeric by item 4 of each
>>    sort lines of pIPList numeric by item 3 of each
>>    sort lines of pIPList numeric by item 2 of each
>>    sort lines of pIPList numeric by item 1 of each
>>    return pIPList
>> end sortIPList
>> Enjoy!
>> Bob S
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:

More information about the Use-livecode mailing list