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



Gordon Beaton wrote:
On Wed, 29 Aug 2007 06:10:46 -0700, Patricia Shanahan wrote:
Roedy Green wrote:
3. concatenate your two String keys into one.
I'd avoid this one unless there is at least one char bit pattern
that cannot appear in the first input, to use as separator.

Why is it necessary to separate them? The cost of not doing so is only
an increased risk of collisions.

In fact that cost might be zero or so negligible that adding the
separator at each operation costs more than the potential collisions
it attempts to avoid.

I'm assuming that the concatenation is only used internally in the
HashMap, and that the separate components are used elsewhere in their
original, separate state.

If it were only for purposes of calculating hashCode(), I would
completely agree. However, my understanding is that this is to be used
as the key in a single key HashMap substituting for a map keyed by the
pair.

In the portion I snipped, the first two items in the list were:

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.

Both of those solutions would treat <"A_B",C> and <"A","B_C"> as
different keys. Both could be present as keys, with different values, at
the same time.

Patricia

.



Relevant Pages

  • Re: [PATCH 0/8] VFS name lookup permission checking cleanup
    ... The aim would be to try to avoid getting that annoying cacheline ping-pong ... around the whole lookup. ... tests that are done for each path component. ... We used to do the common case entirely in the VFS layer, ...
    (Linux-Kernel)
  • Re: Help Adding up multiple calculated cells
    ... This arrangement will avoid the nested limit of 7 in XL2003 ... from a lookup name from a data validation pick list. ... I have 8 columns range named Lic1, Lic2, etc to hold a chosen license ... others will have an entry in one or more of the Lic1-Lic8 fields. ...
    (microsoft.public.excel)
  • Re: VLOOKUP - avoiding left column rule
    ... > VLOOKUP, I the lookup value must always been the left foremost column. ... > Any ideas how to avoid this by using a formula within a vlookup. ... I just use LOOKUP in those cases. ...
    (microsoft.public.excel.misc)
  • Re: Case-insensitive string compare?
    ... I'm not familiar with how python works internally, ... avoid a slightly more verbose lookup later. ... as well be a list of tuples to begin with, to avoid creating a new list. ... case-insensitive lookup, you obviously don't expect this to be an issue. ...
    (comp.lang.python)
  • RE: look up word
    ... returning a work in the cell but not lookup a word and returning a different ... Gary''s Student - gsnu200800 ... I can use Lookup if the first input is a number but this does not seem to ...
    (microsoft.public.excel.misc)