Equivilent of STL Set in D ? ...

KlausO oberhofer at users.sourceforge.net
Sun Oct 22 14:21:38 PDT 2006


KlausO wrote:
> 
> Seems to be an interesting task to get used to the new foreach
> features. I'll give it a try.
> 
> Klaus

Ok, I rewrote the intrusive version to a nonintrusive one.
It has almost the interface you mentioned.

Please note: IMHO, there are some points where the template
needs some refinement.

1. A third template parameter "bool duplicatesAllowed" should be
    added and handled in insert/remove via "static if". Then you
    have multisets at hand !

2. Sometimes it exposes an interface to the internally used nodes
    to be able to access the key/value pairs. A special iterator
    class which could encapsulate the "not found/not inserted"
    state would be better.

3. The insert via opIndexAssign/find via opIndex is IMHO not
    optimal because you could not return the "not found/not inserted"
    state. There are some possibilities to resolve this:

     a) Throw an exception (IMHO, ugly)
     b) Return an empty node
     c) ... any ideas ?

    Using insert like
      if (foo.insert("Jill", 13))
    looks better to me.

Ok, thats it for now. Maybe I find some spare time next week
to adress some of the issues.
Greets

Klaus

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: redblacktree.d
Url: http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20061022/b051e15e/attachment.diff 


More information about the Digitalmars-d-learn mailing list