A single Hashtable for two keys is simpler, easier to maintain than two,
exactly the same speed, and takes very slightly less space.
I don't buy either "simpler", or "easier to maintain". It's a technique that
runs counter to programmer's expectations, and as such should be shunned unless
there's a good reason for it. As an example, the code for iterating over the
elements (values) of the table would be considerably more convoluted than a
programmer would expect if they hadn't realised that you were playing games
with the table's contents.
I can buy "very slightly less space" if you are referring to the constant space
overheads of the two datastructures. I presume that you are not advancing that
as an actual /advantage/ of merging the two indexes, but just happily (and
properly) nit-picking ;-)
I'll enter two caveats against "exactly the same speed". One is that increasing
the capacity and occupancy of a hash table in tandem is only "free" for as long
as you don't exhaust the space of hash values. Obviously the bigger the table,
the more likely that is to happen. The second is that I don't think it's
likely to be true in practice once when you take data cache effects into
account. OTOH, the mix of two types of key might give rise to more even
spreading of the hash values (or, there again, it might be worse...).
Then add in the fact that either:
the two sets of keys have distinct types
or:
the two sets of keys no not have distinct types
both of which cause problems. In the first case you can't express the type of
the table using generics (though I admit that what bothers me is more that it
conceptually messy than that it is statically "unsafe"). In the second case
you have to worry about the possibility of the same "key" appearing twice in
two roles.
I think that all merging the tables is likely to achieve is a significantly
more convoluted expression of a lookup that would be essentially as efficient
using two tables.
-- chris