A case for valueless AA's?
Nick Sabalausky
a at a.a
Tue Mar 29 16:18:52 PDT 2011
"Andrej Mitrovic" <none at none.none> wrote in message
news:imtirq$292g$1 at digitalmars.com...
> 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?
>
> I could just wrap an AA in a custom type that has a nice constructor,
> which takes care of issue #2. But I don't know how to get rid of the
> values, which leaves the issue #1.
I frequently find use for such a thing. I've always used "bool[whatever]"
for that purpose. Piotr's suggestion of "void[0][whatever]" never occurred
to me, I may try that sometime.
More information about the Digitalmars-d
mailing list