a sets implementation

Stephan Diehl stephan.diehl at gmx.net
Wed Feb 7 02:54:30 PST 2007


Michiel wrote:
> Not bad. I like how you have integrated some set operations. I posted my own
> implementation earlier. And while it is much shorter, it doesn't overload any
> operators and is of course not nicely encapsulated like yours.
> 
> I would do some things differently, though. For example:
> 
> * You copy array-elements over one by one. You can also use array.dup.
> * You use a try-catch block for contains(). It's better if you reserve that for
> exceptional circumstances. You can also use the 'in' operator.

that must be a pythonism as try ... except is a common idiom :-)

> * I would overload the 'in' operator anyway.

I tried. But for some reason, the compiler insists on associative arrays 
when using the 'in' operator. And when used with associative arrays, it 
will test the values, not the keys. (it's just the other way round in 
python: the 'in' operator checks for the keys, which actually does make 
some sense).



More information about the Digitalmars-d mailing list