|
Quick Lists
|
|
Bug ID:
|
6812862
|
|
Votes
|
0
|
|
Synopsis
|
provide customizable hash() algorithm in HashMap for speed tuning
|
|
Category
|
java:classes_util
|
|
Reported Against
|
|
|
Release Fixed
|
|
|
State
|
11-Closed,
Will Not Fix,
request for enhancement
|
|
Priority:
|
5-Very Low
|
|
Related Bugs
|
|
|
Submit Date
|
04-MAR-2009
|
|
Description
|
A DESCRIPTION OF THE REQUEST :
HashMap always invokes the hashCode() method of the key customer and after optimizes this hash by package private static int hash(int h).
Please provide following additional method for java.util.HashMap, which could be overridden if reasonable:
protected int hash(K key) {
return hash(key.hashCode());
}
and replace all internal calls
hash(key.hashCode())
by
hash(key)
JUSTIFICATION :
See, for example, following String list as keys:
"windows-1250"
"windows-1251"
"windows-1252"
"windows-1253"
...
"IBM01140"
"IBM01141"
"IBM01142"
"IBM01143"
...
Calculation of hash by standard String#hashCode + optimization by static int hash(int h) will waste performance, as only taking the 2 last letters of those keys would suffice for a customer fast hash value.
String#hashCode() method is not overrideable, because String is immutable.
---------- BEGIN SOURCE ----------
For example above, I would like to tune HashMap by following code:
HashMap<String,String> x = new HashMap() {
protected int hash(String key) {
int len = key.length();
return key.charAt(--len) ^ (key.charAt(--len) << 4);
}
};
---------- END SOURCE ----------
Posted Date : 2009-03-04 09:56:50.0
|
|
Work Around
|
N/A
|
|
Evaluation
|
implement a wrapper class for the "key" to customize its hash() & equals() methods
Posted Date : 2009-03-04 16:36:33.0
|
|
Comments
|
Submitted On 05-MAR-2009
UlfZibis
Proposal according the evaluation is only half the battle, because the exta cycles of the internal hash(int) wont be saved and packing + unpacking need some additional cycles + instantiation of numerous objects.
Submitted On 10-APR-2009
UlfZibis
Additionally the workaround by wrapper would be completely impossible thinking about java.util.Properties class, as it would reject wrapper objects because of restriction for String objects as keys.
So this RFE should be understood also for java.util.HashTable and HashSet.
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|
|
|
 |