From f70151d8c7787c54fae12b511710f72f08e3ea2e Mon Sep 17 00:00:00 2001 From: asofold Date: Mon, 28 Sep 2015 13:09:45 +0200 Subject: [PATCH] Use an iterator for remove. --- .../utilities/ds/map/AbstractCoordHashMap.java | 10 ++++++---- .../nocheatplus/utilities/ds/map/CoordHashMap.java | 3 +++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/NCPCommons/src/main/java/fr/neatmonster/nocheatplus/utilities/ds/map/AbstractCoordHashMap.java b/NCPCommons/src/main/java/fr/neatmonster/nocheatplus/utilities/ds/map/AbstractCoordHashMap.java index f9ca00ba..8892f63d 100644 --- a/NCPCommons/src/main/java/fr/neatmonster/nocheatplus/utilities/ds/map/AbstractCoordHashMap.java +++ b/NCPCommons/src/main/java/fr/neatmonster/nocheatplus/utilities/ds/map/AbstractCoordHashMap.java @@ -1,6 +1,7 @@ package fr.neatmonster.nocheatplus.utilities.ds.map; import java.util.Arrays; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -143,14 +144,15 @@ public abstract class AbstractCoordHashMap it = bucket.iterator(); + while (it.hasNext()) { + final E entry = it.next(); if (entry.hash == hash && x == entry.x && z == entry.z && y == entry.y) { - bucket.remove(entry); + it.remove(); + size--; if (bucket.isEmpty()) { entries[slot] = null; } - size--; return entry.value; } } diff --git a/NCPCommons/src/main/java/fr/neatmonster/nocheatplus/utilities/ds/map/CoordHashMap.java b/NCPCommons/src/main/java/fr/neatmonster/nocheatplus/utilities/ds/map/CoordHashMap.java index d3e0201c..783c071a 100644 --- a/NCPCommons/src/main/java/fr/neatmonster/nocheatplus/utilities/ds/map/CoordHashMap.java +++ b/NCPCommons/src/main/java/fr/neatmonster/nocheatplus/utilities/ds/map/CoordHashMap.java @@ -30,6 +30,9 @@ public class CoordHashMap extends AbstractCoordHashMap */ public static class HashIterator implements Iterator> { + + // TODO: Switch to store an iterator? + private final CoordHashMap map; private final List>[] entries;