Permalink
Browse files

Apply PersistentHashMap.transient fix from mainline

Fix dissoccing colliding values in a transient hashmap (CLJ-829)
e76d68dc65bf68f7310cc5e943c9f4ff960249e9
  • Loading branch information...
1 parent 114abef commit c2a5d02a32148321175d101e7aba4854f97ab8ca @jordanlewis jordanlewis committed Aug 17, 2012
Showing with 6 additions and 4 deletions.
  1. +6 −4 src/main/java/com/trifork/clj_ds/PersistentHashMap.java
@@ -1037,8 +1037,7 @@ public INode without(AtomicReference<Thread> edit, int shift, int hash, Object k
return editAndSet(edit, 2*idx+1, n);
if (bitmap == bit)
return null;
- removedLeaf.val = removedLeaf;
- return editAndRemovePair(edit, bit, idx);
+ return editAndRemovePair(edit, bit, idx);
}
if(Util.equals(key, keyOrNull)) {
removedLeaf.val = removedLeaf;
@@ -1193,7 +1192,9 @@ public int findIndex(Object key){
private HashCollisionNode ensureEditable(AtomicReference<Thread> edit){
if(this.edit == edit)
return this;
- return new HashCollisionNode(edit, hash, count, array);
+ Object[] newArray = new Object[2*(count+1)]; // make room for next assoc
+ System.arraycopy(array, 0, newArray, 0, 2*count);
+ return new HashCollisionNode(edit, hash, count, newArray);
}
private HashCollisionNode ensureEditable(AtomicReference<Thread> edit, int count, Object[] array){
@@ -1249,6 +1250,7 @@ public INode without(AtomicReference<Thread> edit, int shift, int hash, Object k
int idx = findIndex(key);
if(idx == -1)
return this;
+ removedLeaf.val = removedLeaf;
if(count == 1)
return null;
HashCollisionNode editable = ensureEditable(edit);
@@ -1451,4 +1453,4 @@ public ISeq next() {
}
}
-}
+}

0 comments on commit c2a5d02

Please sign in to comment.