Forums

Help, how is Set implemented?

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Help, how is Set implemented?

Postby biribau » Wed Mar 24, 2010 4:25 pm

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?
biribau
 
Posts: 5

Re: Help, how is Set implemented?

Postby Charles » Thu Mar 25, 2010 2:50 am

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.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Help, how is Set implemented?

Postby Charles » Thu Mar 25, 2010 7:30 am

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.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Help, how is Set implemented?

Postby biribau » Thu Mar 25, 2010 10:16 am

Thx very much, i'm recently introduced to .net, that's why i didn't know HashSets are in last versions
biribau
 
Posts: 5


Return to Discussion

Who is online

Users browsing this forum: No registered users and 82 guests