[Gambas-user] New feature in the Array classes

Benoît Minisini g4mba5 at gmail.com
Tue Feb 9 20:36:11 CET 2021


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!

-- 
Benoît Minisini


More information about the User mailing list