mirror of
https://github.com/corda/corda.git
synced 2025-01-22 12:28:11 +00:00
fix a few HashMap bugs
1. HashMap.containsValue only checked one hash bucket, which was pretty much useless :) 2. HashMap.MyIterator.remove was broken in that it failed to decrement the size field and it did not update the previousCell field properly, which sometimes led to more than one cell being removed.
This commit is contained in:
parent
19dbc61e9f
commit
f9197cb076
@ -150,13 +150,14 @@ public class HashMap<K, V> implements Map<K, V> {
|
||||
|
||||
public boolean containsValue(Object value) {
|
||||
if (array != null) {
|
||||
int index = array.length - 1;
|
||||
for (Cell<K, V> c = array[index]; c != null; c = c.next()) {
|
||||
for (int i = 0; i < array.length; ++i) {
|
||||
for (Cell<K, V> c = array[i]; c != null; c = c.next()) {
|
||||
if (helper.equal(value, c.getValue())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -450,11 +451,13 @@ public class HashMap<K, V> implements Map<K, V> {
|
||||
|
||||
public Entry<K, V> next() {
|
||||
if (hasNext()) {
|
||||
if (currentCell != null && currentCell.next() != null) {
|
||||
if (currentCell != null) {
|
||||
if (currentCell.next() != null) {
|
||||
previousCell = currentCell;
|
||||
} else {
|
||||
previousCell = null;
|
||||
}
|
||||
}
|
||||
|
||||
currentCell = nextCell;
|
||||
currentIndex = nextIndex;
|
||||
@ -490,6 +493,7 @@ public class HashMap<K, V> implements Map<K, V> {
|
||||
}
|
||||
}
|
||||
currentCell = null;
|
||||
-- size;
|
||||
} else {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user