Hash Table
Benji Smith
dlanguage at benjismith.net
Wed Mar 21 17:28:58 PDT 2007
Mason wrote:
> Ok, I think I may have found a solution.
>
> I'm going to create my Hash Table using the Tango HashSet container. I'm sure I could have used another container, but since my primary interest is speed I'll go with the HashSet.
>
> I'll initialize the Hast Table like so:
>
> alias HashSet!(int) objectSet;
> objectSet[GRID_SIZE] hashTable;
>
> for(int i = 0; i < GRID_SIZE; i++)
> hashTable[i] = new objectSet;
>
> The hashTable[] array represents the entire Hash Table. Each individual bucket in the table is created with a HashSet container, and I'll use a Hash Function to determine which bucket I place my object index into.
>
> Is this a sound method or foolish? My primary goal is speed; I need my Hash Table to be as efficient as possible.
>
> Comments?
>
> Thanks,
> Mason
Hmmmmmm. Sounds like a bad idea to me. Why not just use an associative
array? That's what they're there for.
I can't think of a good reason for creating an array of HashSets. Though
in the past I've used this code as a MultiMap approximation:
HashMap!(KeyType, HashSet!(ValueType))
Describe your application, and I think we can describe a better way of
implementing it than what you're currently doing.
--benji
More information about the Digitalmars-d-learn
mailing list