D library projects

Steven Schveighoffer schveiguy at yahoo.com
Mon Nov 16 03:43:05 PST 2009


On Mon, 16 Nov 2009 02:07:47 -0500, Denis Koroskin <2korden at gmail.com>  
wrote:

> On Mon, 16 Nov 2009 02:16:09 +0300, Steven Schveighoffer  
> <schveiguy at yahoo.com> wrote:
>
>> On Sun, 15 Nov 2009 15:53:08 -0500, BLS <windevguy at hotmail.de> wrote:
>>
>>
>>>
>>> ==
>>> Now : Sorry for my ignorance ... but Why the heck :
>>>
>>> struct RBNode(V)
>>>
>>> instead of :
>>>
>>> struct RBNode(K, V)
>>>
>>
>> It was my way of providing the exact same implementation for TreeMap,  
>> TreeSet, and TreeMultiSet  (same deal between HashMap and HashSet, and  
>> HashMultiSet).  TreeSet and TreeMultiSet have no keys,
>
> I'd say it has no values but keys.

You could look at it that way, but I think it would be just as awkward to  
declare RBNode(K, V) using RBNode!(V, void) and do some weird static-if  
stuff for sets.

>
>> so the basic difference between them is the comparator function for  
>> TreeMap (which is passed in by the class to the impl) compares only the  
>> keys.
>>
>
> That's the key! Maybe I'm missing something, but when do you need to  
> compare values?

In TreeSet.  There are no keys, only values.  Or you could say, the keys  
are the values.  From the point of view of RBNode, it doesn't care, it  
just uses the comparator function given to it.

-Steve



More information about the Digitalmars-d mailing list