[Gambas-user] Get distinct array from large array
Jussi Lahtinen
jussi.lahtinen at gmail.com
Fri Dec 10 05:07:33 CET 2021
You mean no duplicates?
Then this is already faster (no reason to check the count):
yyy = New String[]
For Each xx In xxx
If yyy.Find(xx, gb.Binary) = -1 Then
yyy.Add(xx)
Endif
Next
You may also want to try to sort the array first and then just check
whether next in the iteration is different (if yes, then add it).
Jussi
On Fri, Dec 10, 2021 at 5:54 AM Safiur Rahman <isafiur at gmail.com> wrote:
> Hi
>
> I want to get a string array of distinct items from another string array
> which has large count (about a million). I hope Benoît will add a function
> for this. Till then what can be the fastest way to get array of distinct
> items?
>
> I am using following code to achieve that. But it is slow
>
> Dim yyy As String[]
> Dim xx As String
>
> yyy = New String[]
> For Each xx In xxx
> If yyy.Count = 0 Then
> yyy.Add(xx)
> Else If yyy.Count > 0 Then
> If yyy.Find(xx, gb.Binary) = -1 Then
> yyy.Add(xx)
> Endif
> Endif
> Next
>
> --
> Regards
> Safiur Rahman
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20211210/dcbdb52c/attachment.htm>
More information about the User
mailing list