Re: How can i implements a class like an HashMap but with 2 keys ?



On Tue, 28 Aug 2007 14:02:21 +0200, Rob <nomail@nomail> wrote, quoted
or indirectly quoted someone who said :

i am a newbie, i want to create a class that works like an HashMap but
with 2 keys, get(key1,key2) -> value

Here are three solutions:

1. use two HashMaps on the same set of objects. Then you can look up
by either key.

2. create a Pair class that contains key1 and key2 with an ^ (xor)
combined hashCode. Then Pair is a single key for both building and
lookup. You need both keys to lookup, like a safety deposit box.

3. concatenate your two String keys into one.

See http://mindprod.com/jgloss/hashcode.html
http://mindprod.com/jgloss/hashmap.html
http://mindprod.com/jgloss/hashtable.html
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
.



Relevant Pages

  • Re: transaction disabling
    ... All this is internal to the database. ... couple of fields to the new/changed lookup key values. ... I am doing this as I have a dynamic query building form that users ... The filter keys are higher in the ...
    (microsoft.public.sqlserver.server)
  • Re: Lookup Tables, the right way?
    ... If you are defining a database table that requires a lookup table, ... then the foreign key between the two tables should be a character ... there's the question of surrogate keys versus natural keys. ...
    (comp.databases.theory)
  • Re: Overriding iadd for dictionary like objects
    ... the value, hence the second lookup. ... must effort has gone into optimizing dict lookup. ... I made a DictMixin where the keys are filenames and the values are the ... It was very simple and easy to do thanks to DictMixin. ...
    (comp.lang.python)
  • Re: transaction disabling
    ... query scans the 5 million rows how many of those will actually meet the ... > (from subgroups to group, from fiscal week keys to fiscal month keys, ... The lookup tables are ... By filtering the large table directly by using these stored ...
    (microsoft.public.sqlserver.server)
  • Re: Basic Question for Lookups.
    ... >From Vincent "My advice is, if you find them helpful, use them." ... against lookup fields and other mis-features. ... another very insightful answer from Vincent. ... > foreign keys have no other purpose than to act as keys (which is how I ...
    (microsoft.public.access.tablesdbdesign)