I'm converting a Java app of mine to Gambas and I could not find any
equivalent to Java's Collections.frequency [1].
So I wrote this function for Integer[]:
Private Function Frequency(aArray As Integer[], iValue As Integer) As
Integer
Dim iCount As Integer
Dim iItem As Integer
For Each
Le 18/05/2014 13:44, Patrik Karlsson a écrit :
I'm converting a Java app of mine to Gambas and I could not find any
equivalent to Java's Collections.frequency [1].
So I wrote this function for Integer[]:
Private Function Frequency(aArray As Integer[], iValue As Integer) As
Integer
Dim
For best performance, loop over index from 0 to length-1 instead of using
the For Each construct.
2014-05-18 14:43 GMT+02:00 Benoît Minisini gam...@users.sourceforge.net:
Le 18/05/2014 13:44, Patrik Karlsson a écrit :
I'm converting a Java app of mine to Gambas and I could not find any
Ok, so the module looks like this now, is Variant slower than other native
data types?
Export
Fast
Public Function Frequency(avValues As Variant[], vValue As Variant) As
Integer
Dim i As Integer
Dim iFrequency As Integer
For i = 0 To avValues.Length - 1
If avValues[i] = vValue Then
Yes, Variant is slower than other native data types, as it must always
examine the type of the variable when it is used.
Note that you should write avValues As Variant instead of Variant[],
since a Variant can contain any type (for example any Array). A Variant[]
however is always an array