groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwagenleit...@apache.org
Subject [2/3] groovy git commit: Fix for ManagedDoubleKeyMap when there are hash collisions and entry array must be expanded
Date Tue, 03 May 2016 03:08:27 GMT
Fix for ManagedDoubleKeyMap when there are hash collisions and entry array must be expanded

The existing array was having the first element overwritten instead of using the newly allocated
array.


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/3bcadcf0
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/3bcadcf0
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/3bcadcf0

Branch: refs/heads/master
Commit: 3bcadcf063e52232d15e663f1b3f5511ee78285c
Parents: 01007a3
Author: John Wagenleitner <jwagenleitner@apache.org>
Authored: Mon May 2 19:59:45 2016 -0700
Committer: John Wagenleitner <jwagenleitner@apache.org>
Committed: Mon May 2 20:04:48 2016 -0700

----------------------------------------------------------------------
 .../util/AbstractConcurrentDoubleKeyMap.java       |  4 ++--
 .../groovy/util/ManagedDoubleKeyMapTest.groovy     | 17 +++++++++++++++++
 2 files changed, 19 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/3bcadcf0/src/main/org/codehaus/groovy/util/AbstractConcurrentDoubleKeyMap.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/util/AbstractConcurrentDoubleKeyMap.java b/src/main/org/codehaus/groovy/util/AbstractConcurrentDoubleKeyMap.java
index 6137efc..e83b641 100644
--- a/src/main/org/codehaus/groovy/util/AbstractConcurrentDoubleKeyMap.java
+++ b/src/main/org/codehaus/groovy/util/AbstractConcurrentDoubleKeyMap.java
@@ -140,9 +140,9 @@ public abstract class AbstractConcurrentDoubleKeyMap<K1,K2,V> extends
AbstractCo
                         }
                         final Object[] newArr = new Object[arr.length+1];
                         final Entry<K1,K2,V> res = createEntry(key1,key2, hash);
-                        arr [0] = res;
+                        newArr[0] = res;
                         System.arraycopy(arr, 0, newArr, 1, arr.length);
-                        tab[index] = arr;
+                        tab[index] = newArr;
                         count++; // write-volatile
                         return res;
                     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/3bcadcf0/src/test/org/codehaus/groovy/util/ManagedDoubleKeyMapTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/util/ManagedDoubleKeyMapTest.groovy b/src/test/org/codehaus/groovy/util/ManagedDoubleKeyMapTest.groovy
index 82a90d9..a7e1a97 100644
--- a/src/test/org/codehaus/groovy/util/ManagedDoubleKeyMapTest.groovy
+++ b/src/test/org/codehaus/groovy/util/ManagedDoubleKeyMapTest.groovy
@@ -38,4 +38,21 @@ class ManagedDoubleKeyMapTest extends GroovyTestCase {
         assert map.fullSize() == 0
     }
 
+    void testPutForSameHashBucket() {
+        Object obj1 = new Object() { @Override public int hashCode() { return 42; } }
+        Object obj2 = new Object() { @Override public int hashCode() { return 42; } }
+        Object obj3 = new Object() { @Override public int hashCode() { return 42; } }
+
+        map.put(obj1, obj2, 'obj1')
+        map.put(obj2, obj1, 'obj2')
+        map.put(obj3, obj2, 'obj3')
+
+        assert map.size() == 3
+        assert map.fullSize() == 3
+
+        assert map.get(obj1, obj2) == 'obj1'
+        assert map.get(obj2, obj1) == 'obj2'
+        assert map.get(obj3, obj2) == 'obj3'
+    }
+
 }


Mime
View raw message