Use an iterator for remove.

This commit is contained in:
asofold 2015-09-28 13:09:45 +02:00
parent 9efcf01766
commit f70151d8c7
2 changed files with 9 additions and 4 deletions

View File

@ -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<V, E extends fr.neatmonster.nocheatpl
return null;
}
else {
for (int i = 0; i < bucket.size(); i++) {
final E entry = bucket.get(i);
final Iterator<E> 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;
}
}

View File

@ -30,6 +30,9 @@ public class CoordHashMap<V> extends AbstractCoordHashMap<V, fr.neatmonster.noch
* @param <V>
*/
public static class HashIterator<V> implements Iterator<Entry<V>> {
// TODO: Switch to store an iterator?
private final CoordHashMap<V> map;
private final List<HashEntry<V>>[] entries;