Platforms to show: All Mac Windows Linux Cross-Platform

Back to SortMBS module.

Previous items

SortMBS.SortMBS(extends theArray() as Int64, descending as boolean = false)   New in 24.2

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Sort MBS Util Plugin 24.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Sorts an array.
Example
Dim test() As Integer = Array(5, -2, 3, -4, 1)

test.SortMBS

Break // see in debugger

// now reverse it
test.SortMBS True

Break // see in debugger

Does nothing for arrays with theArray.count < 2.
Pass true for descending to reverse the order.

See also:

SortMBS.SortMBS(extends theArray() as Variant, theDelegate as SortVariantDelegateVariantMBS, descending as boolean = false)   New in 24.2

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Sort MBS Util Plugin 24.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Sorts an array using a delegate to compare.

Does nothing for arrays with theArray.count < 2.
Pass true for descending to reverse the order.

Your delegate should be fast and return 0 if both values are equal, 1 if first value is bigger or -1 if first value is smaller.

See also:

SortMBS.SumArrayMBS(source() as Currency, sourceIndex as Integer = 0, sourceCount as Integer = -2, CheckOverflow as Boolean = false) as Currency

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Sort MBS Util Plugin 24.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Sums up all the numbers in the array.
Example
Dim v() As Currency

// just sum up some currency values
v.Add 123.4567
v.Add 1
v.add 0
v.add -56
v.add 4567

Var m1 As Double = Microseconds
Dim sum1 As Currency = SumArrayMBS(v, True)
Dim m2 As Double = Microseconds
Dim sum2 As Currency = SumArrayMBS(v, False)
Dim m3 As Double = Microseconds

Var d1 As Double = m2-m1
Dim d2 As Double = m3-m2
// overflow checking can make it 100 times slower

// try to cause an overflow with huge numbers
v.add 100000000000000.0000
v.add 200000000000000.0000
v.add 300000000000000.0000
v.add 400000000000000.0000

Var sum3 As Currency = SumArrayMBS(v, False)
Dim sum4 As Currency = SumArrayMBS(v, True)

Break

You can limit range by passing in a source index and source count.
If sourceCount is -2, we sum up whole array - sourceIndex.
Pass true for overflow check to detect overflows for each addition. Otherwise pass false for better performance.
Returns the sum of all values.

See also:

SortMBS.SumArrayMBS(source() as Double, sourceIndex as Integer = 0, sourceCount as Integer = -2) as Double

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Sort MBS Util Plugin 24.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Sums up all the numbers in the array.
Example
Const u = 99999
Dim v(u) As Double

For i As Integer = 0 To u
v(i) = i
Next

Var m1 As Double = Microseconds
Dim sumPlugin As Int64 = SumArrayMBS(v)
Dim m2 As Double = Microseconds
Dim sumXojo As Double
For i As Integer = 0 To u
sumXojo = sumXojo + v(i)
next
Dim m3 As Double = Microseconds

Var timePlugin As Double = m2-m1
Dim timeXojo As Double = m3-m2
// plugin is faster than Xojo code

Break

You can limit range by passing in a source index and source count.
If sourceCount is -2, we sum up whole array - sourceIndex.
Returns the sum of all values.

See also:

SortMBS.SumArrayMBS(source() as Int64, sourceIndex as Integer = 0, sourceCount as Integer = -2, CheckOverflow as Boolean = false) as Int64

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Sort MBS Util Plugin 24.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Sums up all the numbers in the array.
Example
Dim v() As Int64

// just sum up some currency values
v.Add 1234567
v.Add 1
v.add 0
v.add -56
v.add 4567

Var m1 As Double = Microseconds
Dim sum1 As Int64 = SumArrayMBS(v, True)
Dim m2 As Double = Microseconds
Dim sum2 As Int64 = SumArrayMBS(v, False)
Dim m3 As Double = Microseconds

Var d1 As Double = m2-m1
Dim d2 As Double = m3-m2
// overflow checking can make it 100 times slower

// try to cause an overflow with huge numbers
v.add 1000000000000000000
v.add 2000000000000000000
v.add 3000000000000000000
v.add 4000000000000000000

Var sum3 As Int64 = SumArrayMBS(v, False)
Dim sum4 As Int64 = SumArrayMBS(v, True)

Break

You can limit range by passing in a source index and source count.
If sourceCount is -2, we sum up whole array - sourceIndex.
Pass true for overflow check to detect overflows for each addition. Otherwise pass false for better performance.
Returns the sum of all values.

See also:

SortMBS.SumArrayMBS(source() as UInt64, sourceIndex as Integer = 0, sourceCount as Integer = -2, CheckOverflow as Boolean = false) as UInt64

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Sort MBS Util Plugin 24.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Sums up all the numbers in the array.
Example
Const u = 99999
Dim v(u) As UInt64

For i As Integer = 0 To u
v(i) = i
Next

Var m1 As Double = Microseconds
Dim sumPlugin As UInt64 = SumArrayMBS(v, False)
Dim m2 As Double = Microseconds
Dim sumPluginOverflowChecked As UInt64 = SumArrayMBS(v, True)
Dim m3 As Double = Microseconds
Dim sumXojo As UInt64
For i As Integer = 0 To u
sumXojo = sumXojo + v(i)
Next
Dim m4 As Double = Microseconds


Var timePlugin As Double = m2-m1
Dim timePluginOverflowChecked As Double = m3-m2
Dim timeXojo As Double = m4-m3
// plugin is faster than Xojo code

Break

You can limit range by passing in a source index and source count.
If sourceCount is -2, we sum up whole array - sourceIndex.
Pass true for overflow check to detect overflows for each addition. Otherwise pass false for better performance.
Returns the sum of all values.

See also:

Previous items

The items on this page are in the following plugins: MBS Util Plugin.


The biggest plugin in space...