[Gambas-devel] Please Benoit i want this !!

Benoît Minisini gambas at ...1...
Fri Nov 28 21:27:09 CET 2014


Le 28/11/2014 21:20, Tobias Boege a écrit :
> On Fri, 28 Nov 2014, Beno?t Minisini wrote:
>> Le 26/10/2014 11:53, Fabien Bodard a ?crit :
>>> Private Function GetDiffArray(Array1 As Integer[], Array2 As
>>> Integer[]) As Integer[]
>>>
>>>     Dim aRet As New Integer[]
>>>     Dim i As Integer
>>>
>>>     For Each i In Array2
>>>       If Array1.Exist(i) Then Continue
>>>       aRet.Add(i)
>>>     Next
>>>     Return aRet
>>>
>>> End
>>>
>>>
>>>
>>> Is it possible to add this in a native way :
>>>
>>> MyArray1.Diff(MyArray2) as array ?
>>>
>>>
>>>
>>> For example in a string it will give
>>>
>>> Destination to do :
>>> [Dest1, Dest2, Dest3, Dest4]
>>>
>>> Destination Done
>>> [Dest1, Dest3]
>>>
>>> Dest remain :
>>> [Dest2, Dest4]
>>>
>>>
>>> I use this to manage a doc cache. In the view i have for example Doc10
>>> to Doc 16 showed.  If i scroll then the doclist change ... so i have
>>> to remove a part of the doc from the cache and then charge another
>>> one.
>>>
>>>
>>> Regards,
>>> Fabien
>>>
>>
>> This is not simple. You want set operators on arrays, and arrays are not
>> set. They can have the same elements more than once.
>>
>> For example, if one set operator need to remove an element from an
>> array, what should it do if the element is included twice? Remove the
>> first one? Remove both?
>>
>> Maybe a Set class? I don't know if Tobias put a Set class in its gb.data
>> component...
>>
>
> I haven't. I do want to add one though. I didn't come across implementation
> techniques other than a hashtable yet and don't know if there are better
> ones. Especially because a set needs to identify arbitrary objects...
>
> Regards,
> Tobi
>

You need access to the equality operator from the component (especially 
for objects). As for the implementation, hash table is the better except 
for very small sets (when comparing with each element is faster than the 
hash table management), or sets of small integer, where an array of bits 
allows direct access.

Regards,

-- 
Benoît Minisini




More information about the Devel mailing list