[Gambas-user] Feature request: Array.Frequency

Patrik Karlsson pata.karlsson at ...626...
Sun May 18 16:04:20 CEST 2014


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
      Inc iFrequency
    Endif
  Next

  Return iFrequency

End



2014-05-18 14:50 GMT+02:00 Emil Lenngren <emil.lenngren at ...626...>:

> 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 <gambas at ...1...>:
>
> > 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 iCount As Integer
> > >    Dim iItem As Integer
> > >
> > >    For Each iItem In aArray
> > >      If iItem = iValue Then
> > >        Inc iCount
> > >      Endif
> > >    Next
> > >
> > >    Return iCount
> > >
> > > End
> > >
> > > Would it be possible to add Frequency as a read only property to
> > gb.Array?
> > >
> > > /Patrik
> > >
> >
> > Why don't you do that in Gambas using JIT compiler ?
> >
> > --
> > Benoît Minisini
> >
> >
> >
> ------------------------------------------------------------------------------
> > "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
> > Instantly run your Selenium tests across 300+ browser/OS combos.
> > Get unparalleled scalability from the best Selenium testing platform
> > available
> > Simple to use. Nothing to install. Get started now for free."
> > http://p.sf.net/sfu/SauceLabs
> > _______________________________________________
> > Gambas-user mailing list
> > Gambas-user at lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/gambas-user
> >
>
> ------------------------------------------------------------------------------
> "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
> Instantly run your Selenium tests across 300+ browser/OS combos.
> Get unparalleled scalability from the best Selenium testing platform
> available
> Simple to use. Nothing to install. Get started now for free."
> http://p.sf.net/sfu/SauceLabs
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>



More information about the User mailing list