A case for valueless AA's?
Jonathan M Davis
jmdavisProg at gmx.com
Tue Mar 29 17:37:45 PDT 2011
On 2011-03-29 14:34, dsimcha wrote:
> == Quote from Andrej Mitrovic (none at none.none)'s article
>
> > Here's a little benchmark of Associative Arrays and Dynamic Arrays. I'm
> > showing
>
> traversal and lookup speed. The `static this()` is used to create a random
>
> collection of words which get stored in the two arrays:
> > https://gist.github.com/893340
> > Hash lookups are naturally very fast. So I am inclined to use hashes for
> > some of
>
> my code, but there's a few problems:
> > 1. I'm wasting memory. I don't need the values, I only need the keys. But
> > I
>
> can't declare a void[string] hash.
>
> > 2. AA literals are awkward to write if you don't need the values:
> > Aa = ["foo":0, "bar":0, "car":0,
> >
> > "dar":0, "mar":0, "doo":0];
> >
> > So there's redundancy there.
> > Anyhow, would this be a good case for valueless AA's? Is that even
> > possible?
>
> They're called sets. In Java I think they're named HashSet and TreeSet.
> In Python they're just named Set. Like AAs, the common ways to implement
> them are via hashing and balanced binary trees. They are usually fleshed
> out with operations like union, intersection and difference. I'm not sure
> whether these belong in the core language as an extension of AAs but if
> not they definitely belong in std.container.
We now have std.container.RedBlackTree, which can be used as a set, but it is
a tree rather than a hash table.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list