Please check out our SortMBS module in MBS Xojo Plugins. It contains optimized array methods for a few things. These functions are highly optimized and usually magnitudes faster than doing it in Xojo code yourself.
We have these functions overloading arrays directly:
method AddMBS(extends array1() as Type, array2() as Type)
method CopyMBS(extends source() as Color, dest() as Color, sourceIndex as Integer = 0, sourceCount as Integer = -2, destIndex as Integer = 0)
method EqualsMBS(extends array1() as Type, array2() as Type, array1offset as Integer = 0, count as Integer = -2, array2offset as Integer = 0) as Boolean
method ReverseMBS(extends theArray() as Type)
method SortMBS(extends theArray() as Type, descending as Boolean = false)
method SortMBS(extends theArray() as Type, theDelegate as SortVariantDelegateTypeMBS, descending as Type = false)
method SumMBS(extends source() as Type, sourceIndex as Integer = 0, sourceCount as Integer = -2) as Int64
The math functions like sum are implemented for Boolean, Currency, Double, Int32, Int64, Single, UInt32 and UInt64. The AddMBS function will append the values to another array. The CopyMBS will copy from one array to another array, optionally only a range of values.
And also you can call them without overloading and pass the arrays as parameter:
method AddArrayMBS(array1() as Type, array2() as Type)
method CopyArrayMBS(source() as Type, dest() as Type, sourceIndex as Integer = 0, sourceCount as Integer = -2, destIndex as Integer = 0)
method EqualsArrayMBS(array1() as Type, array2() as Type, array1offset as Integer = 0, count as Integer = -2, array2offset as Integer = 0) as Boolean
method SortArrayMBS(theArray() as Type, descending as boolean = false)
method SortArrayMBS(theArray() as Type, theDelegate as SortVariantDelegateBooleanMBS, descending as boolean = false)
method SumArrayMBS(source() as Type, sourceIndex as Integer = 0, sourceCount as Integer = -2) as Int64
Sorting an array is possibile with ascending or descending order and optionally you can have a delegate to decide. The EqualsMBS function compares two arrays or optionally just two ranges.
If you’d write this in Xojo directly, you would have to call a function to get or set a value, which we can optimize in C++. We avoid most of the object locking and bound checking since we check the range once and not for each access.
Types | Reverse | Sum | Equals | Add (Append) | Copy | Sort |
---|---|---|---|---|---|---|
Boolean | X | X | X | X | X | X |
Color | X | X | X | X | X | |
Currency | X | X | X | X | X | X |
Date | X | * | * | X | ||
DateTime | * | * | * | X | ||
Double | X | X | X | X | X | X |
Int32 | X | X | X | X | X | X |
Int64 | X | X | X | X | X | X |
Object | * | X | X | |||
Ptr | X | X | X | X | X | |
Single | X | X | X | X | X | X |
String | X | X | X | X | X | |
UInt32 | X | X | X | X | X | X |
UInt64 | X | X | X | X | X | X |
Variant | * | * | X |
The stars indicate the functions we add for 25.1. Let us know if you miss another data type for us to add or maybe another cool idea for a method to make here.