[Gambas-user] New feature in the Array classes

Bruce Steers bsteers4 at gmail.com
Tue Feb 9 20:51:48 CET 2021


On Tue, 9 Feb 2021 at 19:37, Benoît Minisini <g4mba5 at gmail.com> wrote:

> Hi,
>
> Following the recent optimizations on the array classes (that apparently
> made array access about 15% faster), I added a new property named
> "Sorted" to the array classes.
>
> If you set that property to TRUE, it will tell the interpreter that the
> array is sorted.
>
> Then, the Find() and Exist() method will use a faster binary search
> algorithm instead of a sequential one.
>
> But it's up to you to maintain the array sorted. If Array.Sorted is
> TRUE, and the array is not actually sorted, the result of Find() and
> Exist() will be false.
>
> If Find() does not find the element, instead of returning -1, it will
> return a negative value indicating where the unfound element must be
> inserted in the array to keep it sorted.
>
> If Find() returns the value -N, then the unfound element must be
> inserted at position is (N - 1).
>
> Enjoy!
>

Thank you :)

Does Array.Add() support negative values?
A quick...
*myArray.Add(sText , myArray.Find(sText))*
to keep things sorted.
or might a new
*myArray.AddSorted(sText)* command be possible for us?

Many thanks Ben :)
BruceS
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20210209/b5fdc835/attachment.htm>


More information about the User mailing list