Revert matt's changes

Let's not break Fawe, thanks
This commit is contained in:
N0tMyFaultOG
2020-06-13 18:48:57 +02:00
parent 56f29a3962
commit bfcc6184ad
75 changed files with 687 additions and 980 deletions

View File

@ -19,6 +19,7 @@
package com.sk89q.worldedit.util.collection;
import com.google.common.collect.AbstractIterator;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BaseBlock;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
@ -35,7 +36,6 @@ import java.util.AbstractSet;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Set;
import java.util.function.BiConsumer;
@ -43,7 +43,6 @@ import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;
import static com.google.common.base.Preconditions.checkState;
import static com.sk89q.worldedit.math.BitMath.fixSign;
import static com.sk89q.worldedit.math.BitMath.mask;
@ -52,6 +51,12 @@ import static com.sk89q.worldedit.math.BitMath.mask;
*/
public class BlockMap<V> extends AbstractMap<BlockVector3, V> {
/* =========================
IF YOU MAKE CHANGES TO THIS CLASS
Re-run BlockMapTest with the blockmap.fulltesting=true system property.
Or just temporarily remove the annotation disabling the related tests.
========================= */
public static <V> BlockMap<V> create() {
return create(() -> new Int2ObjectOpenHashMap<>(64, 0.9f));
}
@ -240,65 +245,26 @@ public class BlockMap<V> extends AbstractMap<BlockVector3, V> {
entrySet = es = new AbstractSet<Entry<BlockVector3, V>>() {
@Override
public Iterator<Entry<BlockVector3, V>> iterator() {
return new Iterator<Entry<BlockVector3,V>>() {
return new AbstractIterator<Entry<BlockVector3, V>>() {
private final ObjectIterator<Long2ObjectMap.Entry<Int2ObjectMap<V>>> primaryIterator
= Long2ObjectMaps.fastIterator(maps);
private Long2ObjectMap.Entry<Int2ObjectMap<V>> currentPrimaryEntry;
private long currentGroupKey;
private ObjectIterator<Int2ObjectMap.Entry<V>> secondaryIterator;
private boolean finished;
private LazyEntry next;
@Override
public boolean hasNext() {
if (finished) {
return false;
}
if (next == null) {
LazyEntry proposedNext = computeNext();
if (proposedNext == null) {
finished = true;
return false;
}
next = proposedNext;
}
return true;
}
private LazyEntry computeNext() {
protected Entry<BlockVector3, V> computeNext() {
if (secondaryIterator == null || !secondaryIterator.hasNext()) {
if (!primaryIterator.hasNext()) {
return null;
return endOfData();
}
currentPrimaryEntry = primaryIterator.next();
secondaryIterator = Int2ObjectMaps.fastIterator(currentPrimaryEntry.getValue());
// be paranoid
checkState(secondaryIterator.hasNext(),
"Should not have an empty map entry, it should have been removed!");
Long2ObjectMap.Entry<Int2ObjectMap<V>> next = primaryIterator.next();
currentGroupKey = next.getLongKey();
secondaryIterator = Int2ObjectMaps.fastIterator(next.getValue());
}
Int2ObjectMap.Entry<V> next = secondaryIterator.next();
return new LazyEntry(currentPrimaryEntry.getLongKey(), next.getIntKey(), next.getValue());
}
@Override
public Entry<BlockVector3, V> next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
LazyEntry tmp = next;
next = null;
return tmp;
}
@Override
public void remove() {
secondaryIterator.remove();
// ensure invariants hold
if (currentPrimaryEntry.getValue().isEmpty()) {
// the remove call cleared this map. call remove on the primary iter
primaryIterator.remove();
}
return new LazyEntry(currentGroupKey, next.getIntKey(), next.getValue());
}
};
}
@ -398,14 +364,13 @@ public class BlockMap<V> extends AbstractMap<BlockVector3, V> {
@Override
public V remove(Object key) {
BlockVector3 vec = (BlockVector3) key;
long groupKey = toGroupKey(vec);
Int2ObjectMap<V> activeMap = maps.get(groupKey);
Int2ObjectMap<V> activeMap = maps.get(toGroupKey(vec));
if (activeMap == null) {
return null;
}
V removed = activeMap.remove(toInnerKey(vec));
if (activeMap.isEmpty()) {
maps.remove(groupKey);
maps.remove(toGroupKey(vec));
}
return removed;
}
@ -464,9 +429,7 @@ public class BlockMap<V> extends AbstractMap<BlockVector3, V> {
}
if (o instanceof BlockMap) {
// optimize by skipping entry translations:
@SuppressWarnings("unchecked")
BlockMap<V> other = (BlockMap<V>) o;
return maps.equals(other.maps);
return maps.equals(((BlockMap) o).maps);
}
return super.equals(o);
}

View File

@ -91,7 +91,6 @@ class Int2BaseBlockMap extends AbstractInt2ObjectMap<BaseBlock> {
= Int2IntMaps.fastIterator(commonMap);
private final ObjectIterator<Entry<BaseBlock>> uncommonIter
= Int2ObjectMaps.fastIterator(uncommonMap);
private boolean lastNextFromCommon = false;
@Override
public boolean hasNext() {
@ -102,26 +101,15 @@ class Int2BaseBlockMap extends AbstractInt2ObjectMap<BaseBlock> {
public Entry<BaseBlock> next() {
if (commonIter.hasNext()) {
Int2IntMap.Entry e = commonIter.next();
lastNextFromCommon = true;
return new BasicEntry<>(
e.getIntKey(), assumeAsBlock(e.getIntValue())
);
}
if (uncommonIter.hasNext()) {
lastNextFromCommon = false;
return uncommonIter.next();
}
throw new NoSuchElementException();
}
@Override
public void remove() {
if (lastNextFromCommon) {
commonIter.remove();
} else {
uncommonIter.remove();
}
}
};
}

View File

@ -30,54 +30,49 @@ import java.util.Iterator;
class VectorPositionList implements PositionList {
private final IntList delegateX = new IntArrayList();
private final IntList delegateY = new IntArrayList();
private final IntList delegateZ = new IntArrayList();
private final IntList delegate = new IntArrayList();
@Override
public BlockVector3 get(int index) {
int ri = index * 3;
return BlockVector3.at(
delegateX.getInt(index),
delegateY.getInt(index),
delegateZ.getInt(index));
delegate.getInt(ri),
delegate.getInt(ri + 1),
delegate.getInt(ri + 2));
}
@Override
public void add(BlockVector3 vector) {
delegateX.add(vector.getX());
delegateY.add(vector.getY());
delegateZ.add(vector.getZ());
delegate.add(vector.getX());
delegate.add(vector.getY());
delegate.add(vector.getZ());
}
@Override
public int size() {
return delegateX.size();
return delegate.size();
}
@Override
public void clear() {
delegateX.clear();
delegateY.clear();
delegateZ.clear();
delegate.clear();
}
@Override
public Iterator<BlockVector3> iterator() {
return new AbstractIterator<BlockVector3>() {
private final IntIterator iteratorX = delegateX.iterator();
private final IntIterator iteratorY = delegateY.iterator();
private final IntIterator iteratorZ = delegateZ.iterator();
private final IntIterator iterator = delegate.iterator();
@Override
protected BlockVector3 computeNext() {
if (!iteratorX.hasNext()) {
if (!iterator.hasNext()) {
return endOfData();
}
return BlockVector3.at(
iteratorX.nextInt(),
iteratorY.nextInt(),
iteratorZ.nextInt());
iterator.nextInt(),
iterator.nextInt(),
iterator.nextInt());
}
};
}
@ -86,19 +81,17 @@ class VectorPositionList implements PositionList {
public Iterator<BlockVector3> reverseIterator() {
return new AbstractIterator<BlockVector3>() {
private final IntListIterator iteratorX = delegateX.listIterator(delegateX.size());
private final IntListIterator iteratorY = delegateY.listIterator(delegateY.size());
private final IntListIterator iteratorZ = delegateZ.listIterator(delegateZ.size());
private final IntListIterator iterator = delegate.listIterator(delegate.size());
@Override
protected BlockVector3 computeNext() {
if (!iteratorX.hasPrevious()) {
if (!iterator.hasPrevious()) {
return endOfData();
}
return BlockVector3.at(
iteratorX.previousInt(),
iteratorY.previousInt(),
iteratorZ.previousInt());
iterator.previousInt(),
iterator.previousInt(),
iterator.previousInt());
}
};
}

View File

@ -31,7 +31,13 @@ public class TaskStateComparator implements Comparator<Task<?>> {
public int compare(com.sk89q.worldedit.util.task.Task<?> o1, Task<?> o2) {
int ordinal1 = o1.getState().ordinal();
int ordinal2 = o2.getState().ordinal();
return Integer.compare(ordinal1, ordinal2);
if (ordinal1 < ordinal2) {
return -1;
} else if (ordinal1 > ordinal2) {
return 1;
} else {
return 0;
}
}
}