Page 1 of 1

Help, how is Set implemented?

PostPosted: Wed Mar 24, 2010 4:25 pm
by biribau
I like to have Sets builtin in the language. I like to have set literals. But i don't think necesary to build them internally as *special* objects, other than the ones included in .NET library. Well not really, but i fell in a problem. I have a set of Tuple<of int, int>, but Set havent got any constructor passing the comparator of elements, like the one in .NET.
Possible solutions are
    - To use HashSet of System.Collection? - I can't, dont know why.
    - To use a Dictionary with a Compare-objects object using keys as elements and using dummy elements. It works but it's a botch-up.
Why Set is not implemented as HashSet in .NET library?

Re: Help, how is Set implemented?

PostPosted: Thu Mar 25, 2010 2:50 am
by Charles
Because there was no HashSet in .NET 2.0 and Cobra is still targeting that. I'll look into .NET 3.0 & 3.5 support after the upcoming release (was already planning on it). In the mean time, the quickest fix is probably for me to add that initializer. I'll take a look.

Re: Help, how is Set implemented?

PostPosted: Thu Mar 25, 2010 7:30 am
by Charles
Set<of T> now has the following initializers:
class Set<of T> ...
cue init
cue init(capacity as int)
cue init(items as IEnumerable<of T>)
cue init(comparer as IEqualityComparer<of T>)
cue init(items as IEnumerable<of T>?, comparer as IEqualityComparer<of T>?)
cue init(capacity as int, items as IEnumerable<of T>?, comparer as IEqualityComparer<of T>?)

I didn't have time for extensive testing, although the Set unit tests and Cobra regression tests all pass. Let me know if you have any problems.

Re: Help, how is Set implemented?

PostPosted: Thu Mar 25, 2010 10:16 am
by biribau
Thx very much, i'm recently introduced to .net, that's why i didn't know HashSets are in last versions