C
caultonpos
Hi,
I have a common need to keep a small cache of values which are often
identified by two or more long values.
e.g. (1,2) ---- > "Abc"
(1,9) -----> "Def"
For performance I like using a hashtable but to use it I do this:
public void addToCache(Long nbr1, Long nbr2, String value) {
StringBuffer sb = new StringBuffer(32);
sb.append(nbr1);
sb.append(":");
sb.append(nbr2);
hashtable.put (sb.toString(), value);
}
or something similar to that. The point is to make the key unique I
create a String. I would imagine lookups would be more efficient if
the key was not a String but a number. But how to make a unique
number from these two. Perhaps if I knew both numbers would be less
than a billion then (nbr1 * 1,000,000,00 + nbr2) but that seems a
little clunky.
Is there a well defined method to create a single unique number based
upon two values?
thanks!
Greg
I have a common need to keep a small cache of values which are often
identified by two or more long values.
e.g. (1,2) ---- > "Abc"
(1,9) -----> "Def"
For performance I like using a hashtable but to use it I do this:
public void addToCache(Long nbr1, Long nbr2, String value) {
StringBuffer sb = new StringBuffer(32);
sb.append(nbr1);
sb.append(":");
sb.append(nbr2);
hashtable.put (sb.toString(), value);
}
or something similar to that. The point is to make the key unique I
create a String. I would imagine lookups would be more efficient if
the key was not a String but a number. But how to make a unique
number from these two. Perhaps if I knew both numbers would be less
than a billion then (nbr1 * 1,000,000,00 + nbr2) but that seems a
little clunky.
Is there a well defined method to create a single unique number based
upon two values?
thanks!
Greg