diff options
author | Sven Gothel <[email protected]> | 2013-03-12 17:50:22 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-03-12 17:50:22 +0100 |
commit | 1a4514accc8f61ab7ff5fe8c82d22a5ef356c865 (patch) | |
tree | e1819d6baabdb1a0d53b0078b89fa1e572c7dee8 /src/java/com/jogamp/common/util/IntIntHashMap.java | |
parent | 692ee1477a5422cb119070ecd87321833c302873 (diff) |
Fix Long*HashMap impl. of IntIntHashMap: Better 64bit hash value, using new HashUtil.
Introduce markup: /*keyHash*/(.*)/*keyHash*/ allowing Long*HashMap to inject hash function for 64bit value.
Diffstat (limited to 'src/java/com/jogamp/common/util/IntIntHashMap.java')
-rw-r--r-- | src/java/com/jogamp/common/util/IntIntHashMap.java | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/java/com/jogamp/common/util/IntIntHashMap.java b/src/java/com/jogamp/common/util/IntIntHashMap.java index bd5529e..7909478 100644 --- a/src/java/com/jogamp/common/util/IntIntHashMap.java +++ b/src/java/com/jogamp/common/util/IntIntHashMap.java @@ -207,8 +207,8 @@ public class /*name*/IntIntHashMap/*name*/ implements Cloneable, // @SuppressWarnings(value="cast") public boolean containsKey(/*key*/int/*key*/ key) { - Entry[] t = this.table; - int index = (int) (key & mask); + final Entry[] t = this.table; + final int index = /*keyHash*/key/*keyHash*/ & mask; for (Entry e = t[index]; e != null; e = e.next) { if (e.key == key) { return true; @@ -223,8 +223,8 @@ public class /*name*/IntIntHashMap/*name*/ implements Cloneable, */ // @SuppressWarnings(value="cast") public /*value*/int/*value*/ get(/*key*/int/*key*/ key) { - Entry[] t = this.table; - int index = (int) (key & mask); + final Entry[] t = this.table; + final int index = /*keyHash*/key/*keyHash*/ & mask; for (Entry e = t[index]; e != null; e = e.next) { if (e.key == key) { return e.value; @@ -240,7 +240,7 @@ public class /*name*/IntIntHashMap/*name*/ implements Cloneable, // @SuppressWarnings(value="cast") public /*value*/int/*value*/ put(/*key*/int/*key*/ key, /*value*/int/*value*/ value) { final Entry[] t = this.table; - int index = (int) (key & mask); + final int index = /*keyHash*/key/*keyHash*/ & mask; // Check if key already exists. for (Entry e = t[index]; e != null; e = e.next) { if (e.key != key) { @@ -254,18 +254,18 @@ public class /*name*/IntIntHashMap/*name*/ implements Cloneable, if (size++ >= threshold) { // Rehash. - int newCapacity = 2 * capacity; + final int newCapacity = 2 * capacity; final Entry[] newTable = new Entry[newCapacity]; - /*key*/int/*key*/ bucketmask = newCapacity - 1; + final int newMask = newCapacity - 1; for (int j = 0; j < t.length; j++) { Entry e = t[j]; if (e != null) { t[j] = null; do { Entry next = e.next; - index = (int) (e.key & bucketmask); - e.next = newTable[index]; - newTable[index] = e; + final int index2 = /*keyHash*/e.key/*keyHash*/ & newMask; + e.next = newTable[index2]; + newTable[index2] = e; e = next; } while (e != null); } @@ -273,7 +273,7 @@ public class /*name*/IntIntHashMap/*name*/ implements Cloneable, table = newTable; capacity = newCapacity; threshold = (int) (newCapacity * loadFactor); - mask = capacity - 1; + mask = newMask; } return keyNotFoundValue; } @@ -296,9 +296,10 @@ public class /*name*/IntIntHashMap/*name*/ implements Cloneable, // @SuppressWarnings(value="cast") public /*value*/int/*value*/ remove(/*key*/int/*key*/ key) { final Entry[] t = this.table; - final int index = (int) (key & mask); + final int index = /*keyHash*/key/*keyHash*/ & mask; Entry prev = t[index]; Entry e = prev; + while (e != null) { Entry next = e.next; if (e.key == key) { |