Sort IP List

classic Classic list List threaded Threaded
32 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Sort IP List

Niggemann, Bernd via use-livecode
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
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sort IP List

Niggemann, Bernd via use-livecode
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 <
[hidden email]> 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
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sort IP List

Niggemann, Bernd via use-livecode
First, your function returns a single line of numbers. With 30,000 lines of input, yours takes 9 ticks, mine 8.

Bob S


> On Jun 29, 2018, at 08:37 , Mike Bonner via use-livecode <[hidden email]> 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 <
> [hidden email]> 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
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sort IP List

Niggemann, Bernd via use-livecode
In reply to this post by Niggemann, Bernd via use-livecode
## 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 <[hidden email]> 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 <
> [hidden email]> 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
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sort IP List

Niggemann, Bernd via use-livecode
A realistic expectation of IP addresses for a given network might only be around 16,535 (class B network) assuming every address was in use, an unlikely scenario. I thought of way to do this for an extremely large number of addresses by reading a large file in 1000 line chunks into 4 columns of a SQL memory database, then querying using concatenation and sorts on the 4 columns, and using limit 1,1000 1001,1000 2001,1000 etc. and writing back to another file. The time to do this of course would be much longer, but it would avoid any memory constraints.

Bob S


> On Jun 29, 2018, at 09:35 , Mike Bonner via use-livecode <[hidden email]> wrote:
>
> ## 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.


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sort IP List

Niggemann, Bernd via use-livecode
Ok, now i'm curious about something.. I know its possible to designate
multiple keys to a single sort using the form..
sort lines of plist  by item 1 of each &  item 2 of each & item 3 of
each & item
4 of each
which works fine.
But changing it to..
sort lines of plist  ascending numeric by item 1 of each &  item 2 of each &
 item 3 of each & item 4 of each  -- reverse this for your desired sort
doesn't sort numerically (even if each key is forced to numeric with a + 0)

BTW, I had to go back to comments in an older version of LC to remember how
to do the multiple-key sorts.

Since it ignores the "numeric" part, if one limits ips to all 3 digit
numbers, the sort works as expected despite sorting as  alpha.

So my question is this.. Would it be a reasonable feature request to adjust
sort so that its multiple key format respects the numeric sort type?


On Fri, Jun 29, 2018 at 10:46 AM Bob Sneidar via use-livecode <
[hidden email]> wrote:

> A realistic expectation of IP addresses for a given network might only be
> around 16,535 (class B network) assuming every address was in use, an
> unlikely scenario. I thought of way to do this for an extremely large
> number of addresses by reading a large file in 1000 line chunks into 4
> columns of a SQL memory database, then querying using concatenation and
> sorts on the 4 columns, and using limit 1,1000 1001,1000 2001,1000 etc. and
> writing back to another file. The time to do this of course would be much
> longer, but it would avoid any memory constraints.
>
> Bob S
>
>
> > On Jun 29, 2018, at 09:35 , Mike Bonner via use-livecode <
> [hidden email]> wrote:
> >
> > ## 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.
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sort IP List

Niggemann, Bernd via use-livecode
Actually, when using the multiple key sort, dont reverse the order since it
does it all in one go.

On Fri, Jun 29, 2018 at 11:29 AM Mike Bonner <[hidden email]> wrote:

> Ok, now i'm curious about something.. I know its possible to designate
> multiple keys to a single sort using the form..
> sort lines of plist  by item 1 of each &  item 2 of each & item 3 of each
> & item 4 of each
> which works fine.
> But changing it to..
> sort lines of plist  ascending numeric by item 1 of each &  item 2 of
> each & item 3 of each & item 4 of each  -- reverse this for your desired
> sort
> doesn't sort numerically (even if each key is forced to numeric with a + 0)
>
> BTW, I had to go back to comments in an older version of LC to remember
> how to do the multiple-key sorts.
>
> Since it ignores the "numeric" part, if one limits ips to all 3 digit
> numbers, the sort works as expected despite sorting as  alpha.
>
> So my question is this.. Would it be a reasonable feature request to
> adjust sort so that its multiple key format respects the numeric sort type?
>
>
> On Fri, Jun 29, 2018 at 10:46 AM Bob Sneidar via use-livecode <
> [hidden email]> wrote:
>
>> A realistic expectation of IP addresses for a given network might only be
>> around 16,535 (class B network) assuming every address was in use, an
>> unlikely scenario. I thought of way to do this for an extremely large
>> number of addresses by reading a large file in 1000 line chunks into 4
>> columns of a SQL memory database, then querying using concatenation and
>> sorts on the 4 columns, and using limit 1,1000 1001,1000 2001,1000 etc. and
>> writing back to another file. The time to do this of course would be much
>> longer, but it would avoid any memory constraints.
>>
>> Bob S
>>
>>
>> > On Jun 29, 2018, at 09:35 , Mike Bonner via use-livecode <
>> [hidden email]> wrote:
>> >
>> > ## 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.
>>
>>
>> _______________________________________________
>> use-livecode mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sort IP List

Niggemann, Bernd via use-livecode
In reply to this post by Niggemann, Bernd via use-livecode
Yes because your ampersand operator is not passing different arguements, it's concatenating the items together so that 10.2.245.6 produces the integer 1022456. But 10.22.2.6 produces 102226 which is smaller, but ought to sort higher. Hence the 4 pass sort.

But you got me thinking, what if you did something like:

set the numberformat to "000"
sort lines of tIPList numeric by \
   value(item 1 of each +0) & \
   value(item 2 of each +0) & \
   value(item 3 of each +0) & \
   value(item 4 of each)

Bob S



> On Jun 29, 2018, at 10:29 , Mike Bonner via use-livecode <[hidden email]> wrote:
>
> sort lines of plist  ascending numeric by item 1 of each &  item 2 of each &
> item 3 of each & item 4 of each  -- reverse this for your desired sort
> doesn't sort numerically (even if each key is forced to numeric with a + 0)


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sort IP List

Niggemann, Bernd via use-livecode
Yeah, no I get runtime error. <sigh>

> On Jun 29, 2018, at 14:09 , Bob Sneidar via use-livecode <[hidden email]> wrote:
>
> Yes because your ampersand operator is not passing different arguements, it's concatenating the items together so that 10.2.245.6 produces the integer 1022456. But 10.22.2.6 produces 102226 which is smaller, but ought to sort higher. Hence the 4 pass sort.
>
> But you got me thinking, what if you did something like:
>
> set the numberformat to "000"
> sort lines of tIPList numeric by \
>   value(item 1 of each +0) & \
>   value(item 2 of each +0) & \
>   value(item 3 of each +0) & \
>   value(item 4 of each)
>
> Bob S


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sort IP List

Niggemann, Bernd via use-livecode
Thx for the clue, I see what you mean.

I had tried to get something similar to your value(item 1 of each +0)
method to work and something wasn't clicking, but after seeing yours, I
think I have it working.

sort lines of tList ascending numeric by (item 1 of each +0) & (item 2 of
each + 0) & (item 3 of each + 0) & (item 4 of each + 0)

The above seems to work fine (and I avoided using value() to avoid an
unnecessary function call), you just have to remember to set the
itemdelimiter to "." otherwise you get the error.  This may be faster
because there aren't a bunch of function calls like my first idea, though
I'm not sure how overhead compares since the numbers must still be
evaluated.

Just did some testing and it seems to be way way faster.  100k lines sort
in 3/4 of a second.

On Fri, Jun 29, 2018 at 3:18 PM Bob Sneidar via use-livecode <
[hidden email]> wrote:

> Yeah, no I get runtime error. <sigh>
>
> > On Jun 29, 2018, at 14:09 , Bob Sneidar via use-livecode <
> [hidden email]> wrote:
> >
> > Yes because your ampersand operator is not passing different arguements,
> it's concatenating the items together so that 10.2.245.6 produces the
> integer 1022456. But 10.22.2.6 produces 102226 which is smaller, but ought
> to sort higher. Hence the 4 pass sort.
> >
> > But you got me thinking, what if you did something like:
> >
> > set the numberformat to "000"
> > sort lines of tIPList numeric by \
> >   value(item 1 of each +0) & \
> >   value(item 2 of each +0) & \
> >   value(item 3 of each +0) & \
> >   value(item 4 of each)
> >
> > Bob S
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sort IP List

Niggemann, Bernd via use-livecode
Oh, the above assumes setting the numberformat to "000" as you specified of
course.

On Fri, Jun 29, 2018 at 4:00 PM Mike Bonner <[hidden email]> wrote:

> Thx for the clue, I see what you mean.
>
> I had tried to get something similar to your value(item 1 of each +0)
> method to work and something wasn't clicking, but after seeing yours, I
> think I have it working.
>
> sort lines of tList ascending numeric by (item 1 of each +0) & (item 2 of
> each + 0) & (item 3 of each + 0) & (item 4 of each + 0)
>
> The above seems to work fine (and I avoided using value() to avoid an
> unnecessary function call), you just have to remember to set the
> itemdelimiter to "." otherwise you get the error.  This may be faster
> because there aren't a bunch of function calls like my first idea, though
> I'm not sure how overhead compares since the numbers must still be
> evaluated.
>
> Just did some testing and it seems to be way way faster.  100k lines sort
> in 3/4 of a second.
>
> On Fri, Jun 29, 2018 at 3:18 PM Bob Sneidar via use-livecode <
> [hidden email]> wrote:
>
>> Yeah, no I get runtime error. <sigh>
>>
>> > On Jun 29, 2018, at 14:09 , Bob Sneidar via use-livecode <
>> [hidden email]> wrote:
>> >
>> > Yes because your ampersand operator is not passing different
>> arguements, it's concatenating the items together so that 10.2.245.6
>> produces the integer 1022456. But 10.22.2.6 produces 102226 which is
>> smaller, but ought to sort higher. Hence the 4 pass sort.
>> >
>> > But you got me thinking, what if you did something like:
>> >
>> > set the numberformat to "000"
>> > sort lines of tIPList numeric by \
>> >   value(item 1 of each +0) & \
>> >   value(item 2 of each +0) & \
>> >   value(item 3 of each +0) & \
>> >   value(item 4 of each)
>> >
>> > Bob S
>>
>>
>> _______________________________________________
>> use-livecode mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sort IP List

Niggemann, Bernd via use-livecode
In reply to this post by Niggemann, Bernd via use-livecode
Yeah mine won't run. I have:

function sortIPList2 pIPList
   set the itemdelimiter to "."
   try
      sort lines of pIPList ascending numeric by (item 1 of each +0) & (item 2 of each + 0) & (item 3 of each + 0) & (item 4 of each + 0)
   catch theError
      breakpoint
   end try
   return pIPList
end sortIPList2

Script hits breakpoint but there is nothing in theError. What version/OS are you running? We may have uncovered an engine anomaly.

Bob S

> On Jun 29, 2018, at 15:00 , Mike Bonner via use-livecode <[hidden email]> wrote:
>
> sort lines of tList ascending numeric by (item 1 of each +0) & (item 2 of
> each + 0) & (item 3 of each + 0) & (item 4 of each + 0)


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sort IP List

Niggemann, Bernd via use-livecode
Wait I know exactly what is wrong. I have a few lines that use CIDR notation ie. 192.168.1.0/24 and THAT is not a number!

Bob S


> On Jun 29, 2018, at 15:13 , Bob Sneidar via use-livecode <[hidden email]> wrote:
>
> Yeah mine won't run. I have:
>
> function sortIPList2 pIPList
>   set the itemdelimiter to "."
>   try
>      sort lines of pIPList ascending numeric by (item 1 of each +0) & (item 2 of each + 0) & (item 3 of each + 0) & (item 4 of each + 0)
>   catch theError
>      breakpoint
>   end try
>   return pIPList
> end sortIPList2
>
> Script hits breakpoint but there is nothing in theError. What version/OS are you running? We may have uncovered an engine anomaly.
>
> Bob S
>
>> On Jun 29, 2018, at 15:00 , Mike Bonner via use-livecode <[hidden email]> wrote:
>>
>> sort lines of tList ascending numeric by (item 1 of each +0) & (item 2 of
>> each + 0) & (item 3 of each + 0) & (item 4 of each + 0)
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sort IP List

Niggemann, Bernd via use-livecode
Yup, that would be it!

On Fri, Jun 29, 2018 at 4:15 PM Bob Sneidar via use-livecode <
[hidden email]> wrote:

> Wait I know exactly what is wrong. I have a few lines that use CIDR
> notation ie. 192.168.1.0/24 and THAT is not a number!
>
> Bob S
>
>
> > On Jun 29, 2018, at 15:13 , Bob Sneidar via use-livecode <
> [hidden email]> wrote:
> >
> > Yeah mine won't run. I have:
> >
> > function sortIPList2 pIPList
> >   set the itemdelimiter to "."
> >   try
> >      sort lines of pIPList ascending numeric by (item 1 of each +0) &
> (item 2 of each + 0) & (item 3 of each + 0) & (item 4 of each + 0)
> >   catch theError
> >      breakpoint
> >   end try
> >   return pIPList
> > end sortIPList2
> >
> > Script hits breakpoint but there is nothing in theError. What version/OS
> are you running? We may have uncovered an engine anomaly.
> >
> > Bob S
> >
> >> On Jun 29, 2018, at 15:00 , Mike Bonner via use-livecode <
> [hidden email]> wrote:
> >>
> >> sort lines of tList ascending numeric by (item 1 of each +0) & (item 2
> of
> >> each + 0) & (item 3 of each + 0) & (item 4 of each + 0)
> >
> >
> > _______________________________________________
> > use-livecode mailing list
> > [hidden email]
> > Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> > http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sort IP List

Niggemann, Bernd via use-livecode
I have good news and bad news!

function sortIPList2 pIPList
   set the itemdelimiter to "."
   try
      sort lines of pIPList ascending numeric \
            by (item 1 of each + 0) & \
            (item 2 of each + 0) & \
            (item 3 of each + 0) & \
            (item 4 of each + 0)
   catch theError
      breakpoint
   end try
   return pIPList
end sortIPList2

With a small subset of data, it doesn't error meaning I have some cruft in the data. Fair enough. The bad news is... IT DOESN'T SORT! LOL!!! Reversing the items does not help either.

Bob S

> On Jun 29, 2018, at 15:16 , Mike Bonner via use-livecode <[hidden email]> wrote:
>
> Yup, that would be it!


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sort IP List

Niggemann, Bernd via use-livecode
Now that is weird because the sort is definitely working for me.    OH
wait, you don't set the numberformat in your function.  Do you set it
elsewhere, and if so, does it stick when the function is called?  The sort
is definitely, no question, working for me.

I generate a list of IPs then in the msg box do this..

set the numberformat to "000"
set the itemdel to "."
put the millisec into tstart
sort lines of tList ascending numeric by (item 1 of each +0) & (item 2 of
each + 0) & (item 3 of each + 0) & (item 4 of each + 0)
put the millisec - tstart
put cr & tList after msg -- the list is sorted.

Not sure why it isn't working for you, but on the off chance its a version
difference, i'm on 9.0, community +, stable.

On Fri, Jun 29, 2018 at 4:33 PM Bob Sneidar via use-livecode <
[hidden email]> wrote:

> I have good news and bad news!
>
> function sortIPList2 pIPList
>    set the itemdelimiter to "."
>    try
>       sort lines of pIPList ascending numeric \
>             by (item 1 of each + 0) & \
>             (item 2 of each + 0) & \
>             (item 3 of each + 0) & \
>             (item 4 of each + 0)
>    catch theError
>       breakpoint
>    end try
>    return pIPList
> end sortIPList2
>
> With a small subset of data, it doesn't error meaning I have some cruft in
> the data. Fair enough. The bad news is... IT DOESN'T SORT! LOL!!! Reversing
> the items does not help either.
>
> Bob S
>
> > On Jun 29, 2018, at 15:16 , Mike Bonner via use-livecode <
> [hidden email]> wrote:
> >
> > Yup, that would be it!
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sort IP List

Niggemann, Bernd via use-livecode
In reply to this post by Niggemann, Bernd via use-livecode
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
  end repeat
  return y
end ip2dec

on mouseUp
  put fld "ips" into s
  sort s numeric by ip2dec(each) # <----
  put s into fld "out"
end mouseUp


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sort IP List

Niggemann, Bernd via use-livecode
Why not just do it directly (avoid the function call) ...

function sortIPList2 pIPList
    set the itemdelimiter to "."
    try
       sort lines of pIPList ascending numeric \
             by (item 1 of each * 16777216) + \
             (item 2 of each *65536) + \
             (item 3 of each *256) + \
             (item 4 of each )
    catch theError
       breakpoint
    end try
    return pIPList
end sortIPList2

or if you prefer ...
    by item 4 of each + 256 * ( item 3 of each + 256 * (item 2 of each + 256 * item 1 of each ))
...

Alex.

On 30/06/2018 00:41, hh via use-livecode 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
>    end repeat
>    return y
> end ip2dec
>
> on mouseUp
>    put fld "ips" into s
>    sort s numeric by ip2dec(each) # <----
>    put s into fld "out"
> end mouseUp
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sort IP List

Niggemann, Bernd via use-livecode
Alex, you win the cookie! 4 ticks for 30,000 IP addresses! If we ever meet at a conference remind me and I will buy you beers. Not saying how namy, just more than one. :-)

Bob S


> On Jun 29, 2018, at 16:54 , Alex Tweedly via use-livecode <[hidden email]> wrote:
>
> Why not just do it directly (avoid the function call) ...
>
> function sortIPList2 pIPList
>   set the itemdelimiter to "."
>   try
>      sort lines of pIPList ascending numeric \
>            by (item 1 of each * 16777216) + \
>            (item 2 of each *65536) + \
>            (item 3 of each *256) + \
>            (item 4 of each )
>   catch theError
>      breakpoint
>   end try
>   return pIPList
> end sortIPList2
>
> or if you prefer ...
>   by item 4 of each + 256 * ( item 3 of each + 256 * (item 2 of each + 256 * item 1 of each ))
> ...
>
> Alex.
>
> On 30/06/2018 00:41, hh via use-livecode 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
>>   end repeat
>>   return y
>> end ip2dec
>>
>> on mouseUp
>>   put fld "ips" into s
>>   sort s numeric by ip2dec(each) # <----
>>   put s into fld "out"
>> end mouseUp
>>
>>
>> _______________________________________________
>> use-livecode mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sort IP List

Niggemann, Bernd via use-livecode
In reply to this post by Niggemann, Bernd via use-livecode
You all are just too darn smart. great solution.

On Fri, Jun 29, 2018 at 5:54 PM Alex Tweedly via use-livecode <
[hidden email]> wrote:

> Why not just do it directly (avoid the function call) ...
>
> function sortIPList2 pIPList
>     set the itemdelimiter to "."
>     try
>        sort lines of pIPList ascending numeric \
>              by (item 1 of each * 16777216) + \
>              (item 2 of each *65536) + \
>              (item 3 of each *256) + \
>              (item 4 of each )
>     catch theError
>        breakpoint
>     end try
>     return pIPList
> end sortIPList2
>
> or if you prefer ...
>     by item 4 of each + 256 * ( item 3 of each + 256 * (item 2 of each +
> 256 * item 1 of each ))
> ...
>
> Alex.
>
> On 30/06/2018 00:41, hh via use-livecode 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
> >    end repeat
> >    return y
> > end ip2dec
> >
> > on mouseUp
> >    put fld "ips" into s
> >    sort s numeric by ip2dec(each) # <----
> >    put s into fld "out"
> > end mouseUp
> >
> >
> > _______________________________________________
> > use-livecode mailing list
> > [hidden email]
> > Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> > http://lists.runrev.com/mailman/listinfo/use-livecode
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
12