A case for valueless AA's?

Andrej Mitrovic none at none.none
Tue Mar 29 14:27:22 PDT 2011


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.


More information about the Digitalmars-d mailing list