hash design problem: both string and int[] keys

Charles Hixson charleshixsn at earthlink.net
Tue Nov 20 11:39:47 PST 2012


I'm trying to figure out how to construct an associative array whose 
keys will be a combination of strings and immutable int[]'s, but every 
approach I've looked at has run into problems.  It should be relatively 
easy, as strings are really just an immutable list of ints, but I 
haven't been able to find how strings are hashed.  (It's looking as if 
the details are handled in C...which makes it difficult.)  I could 
define my own hash code, but I don't find it at all clear what would be 
appropriate given that I don't know the size.  The data is rather 
sparse, so a hash table seems appropriate.  (My only other alternative 
is a database, and that imposes the heavy slowdown of I/O ... even 
though it does automate persistence it doesn't seem like a good tradeoff.)

So far my best idea is to build two tables, and then look at the key 
when a retrieval is attempted to figure out which table it's in.  That 
would probably work, but it feels like a kludge.


More information about the Digitalmars-d-learn mailing list