[Feature Request] Adding to D lang "set" built-in

Jonathan M Davis jmdavisProg at gmx.com
Sun May 6 23:23:16 PDT 2012


On Monday, May 07, 2012 07:05:28 Russel Winder wrote:
> I wonder if the tradition of exposing HashMap and TreeMap was a
> disservice by C++ and Java? Map and Set are programmer level concepts.
> Where there are algorithmic issues that require knowing about trees or
> has tables then the programmer is not working at the map or set level.

???

There are multiple ways to implement a set or a map. If a programmer knows 
their data structures (as one would hope that they would), then they know the 
difference between a hash set and a tree set (or hash map and tree map), and 
they'll pick the one that's most appropriate for what they're doing. And 
because the containers are very similar, it should be quite possible in many 
cases to replace one with the other quite easily - especially if you're using 
templates. That's one of the reasons that Java has the Set interface with 
HashSet and TreeSet implenting it.

std.container is designed with the idea that containers will be named after 
their data structures and _not_ what they're used for. Programmers can then 
select the data structure that best serves their purposes. And I'd be worried 
about any professional programmer who didn't know that you can use a red-black 
tree as a set or a map.

> And the programmer has no control over how D's associative arrays work.

It's clearly a hash map. If they want a tree map, then we have RedBlackTree 
(though we should probably provide a wrapper that makes it easier to use 
RedBlackTree as a map, since it's a bit unwieldy to do that at the moment). I 
don't see the problem.

- Jonathan M Davis


More information about the Digitalmars-d mailing list