Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript electronics |
digitalmars.D - a sets implementation
being new to D (I have a Python background), the first thing to try out was a set implementation. Since there seems to be quite an interest in this topic, I thought to share this implementation even though it's probably quite horrible for the seasoned D programmer :-) The code can be found here: http://codespeak.net/svn/user/stephan/d-hacks/sets.d It tries to capture the look and feel of python sets. Any comment/feedback is quite welcome. Cheers Stephan Feb 07 2007
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. * I would overload the 'in' operator anyway. Feb 07 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. Feb 07 2007
Stephan Diehl wrote:Michiel wrote:* I would overload the 'in' operator anyway. Feb 07 2007
Frits van Bommel wrote:Stephan Diehl wrote:Michiel wrote:* I would overload the 'in' operator anyway. Feb 07 2007
|