mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-04-07 16:26:14 +00:00
BITS BITS EVERYWHERE
This commit is contained in:
@@ -45,7 +45,7 @@ public final class Varint {
|
||||
* {@link #writeUnsignedVarLong(long, DataOutput)} should be used.
|
||||
*
|
||||
* @param value value to encode
|
||||
* @param out to write bytes to
|
||||
* @param out to writeNodeData bytes to
|
||||
* @throws IOException if {@link DataOutput} throws {@link IOException}
|
||||
*/
|
||||
public static void writeSignedVarLong(long value, DataOutput out) throws IOException {
|
||||
@@ -61,7 +61,7 @@ public final class Varint {
|
||||
* instead. This method treats negative input as like a large unsigned value.
|
||||
*
|
||||
* @param value value to encode
|
||||
* @param out to write bytes to
|
||||
* @param out to writeNodeData bytes to
|
||||
* @throws IOException if {@link DataOutput} throws {@link IOException}
|
||||
*/
|
||||
public static void writeUnsignedVarLong(long value, DataOutput out) throws IOException {
|
||||
|
||||
@@ -20,7 +20,6 @@ package com.volmit.iris.util.data.palette;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.atomic.AtomicLongArray;
|
||||
import java.util.function.IntConsumer;
|
||||
|
||||
@@ -141,6 +140,7 @@ public class BitStorage {
|
||||
int var2 = cellIndex(var0);
|
||||
long var3 = this.data.get(var2);
|
||||
int var5 = (var0 - var2 * this.valuesPerLong) * this.bits;
|
||||
|
||||
this.data.set(var2, var3 & (this.mask << var5 ^ 0xFFFFFFFFFFFFFFFFL) | (var1 & this.mask) << var5);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,19 +28,12 @@ import java.util.concurrent.atomic.AtomicReferenceArray;
|
||||
|
||||
public class CrudeIncrementalIntIdentityHashBiMap<K> implements IdMap<K> {
|
||||
public static final int NOT_FOUND = -1;
|
||||
|
||||
private static final Object EMPTY_SLOT = null;
|
||||
|
||||
private static final float LOADFACTOR = 0.8F;
|
||||
|
||||
private AtomicReferenceArray<K> keys;
|
||||
|
||||
private AtomicIntegerArray values;
|
||||
|
||||
private AtomicReferenceArray<K> byId;
|
||||
|
||||
private int nextId;
|
||||
|
||||
private int size;
|
||||
|
||||
public CrudeIncrementalIntIdentityHashBiMap(int var0) {
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
package com.volmit.iris.util.data.palette;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
|
||||
@@ -26,38 +28,40 @@ import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class HashMapPalette<T> implements Palette<T> {
|
||||
private final CrudeIncrementalIntIdentityHashBiMap<T> values;
|
||||
private final KMap<T, Integer> values;
|
||||
private final PaletteResize<T> resizeHandler;
|
||||
private final int bits;
|
||||
private int id;
|
||||
|
||||
public HashMapPalette(int var1, PaletteResize<T> var2) {
|
||||
this.bits = var1;
|
||||
this.resizeHandler = var2;
|
||||
this.values = new CrudeIncrementalIntIdentityHashBiMap<>(1 << var1);
|
||||
this.values = new KMap<>();
|
||||
id = 1;
|
||||
}
|
||||
|
||||
public int idFor(T var0) {
|
||||
int var1 = this.values.getId(var0);
|
||||
if (var1 == -1) {
|
||||
var1 = this.values.add(var0);
|
||||
if (var1 >= 1 << this.bits)
|
||||
{
|
||||
var1 = this.resizeHandler.onResize(this.bits + 1, var0);
|
||||
}
|
||||
if(var0 == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return var1;
|
||||
}
|
||||
|
||||
public boolean maybeHas(Predicate<T> var0) {
|
||||
for (int var1 = 0; var1 < getSize(); var1++) {
|
||||
if (var0.test(this.values.byId(var1)))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return this.values.computeIfAbsent(var0, (k) -> {
|
||||
int newId = id++;
|
||||
|
||||
if (newId >= 1 << this.bits)
|
||||
{
|
||||
Iris.info(newId + " to...");
|
||||
newId = this.resizeHandler.onResize(this.bits + 1, var0);
|
||||
Iris.info(newId + "..");
|
||||
}
|
||||
|
||||
return newId;
|
||||
});
|
||||
}
|
||||
|
||||
public T valueFor(int var0) {
|
||||
return this.values.byId(var0);
|
||||
return this.values.getKey(var0);
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
@@ -66,16 +70,11 @@ public class HashMapPalette<T> implements Palette<T> {
|
||||
|
||||
@Override
|
||||
public void read(List<T> data) {
|
||||
data.forEach(values::add);
|
||||
data.forEach(this::idFor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(List<T> toList) {
|
||||
this.values.iterator().forEachRemaining(i -> {
|
||||
if(i != null)
|
||||
{
|
||||
toList.add(i);
|
||||
}
|
||||
});
|
||||
toList.addAll(values.keySet());
|
||||
}
|
||||
}
|
||||
@@ -56,17 +56,11 @@ public class LinearPalette<T> implements Palette<T> {
|
||||
return resizeHandler.onResize(bits + 1, var0);
|
||||
}
|
||||
|
||||
public boolean maybeHas(Predicate<T> var0) {
|
||||
for (int var1 = 0; var1 < size; var1++) {
|
||||
if (var0.test(values.get(var1)))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public T valueFor(int var0) {
|
||||
if (var0 >= 0 && var0 < size)
|
||||
{
|
||||
return this.values.get(var0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,6 @@ import java.util.function.Predicate;
|
||||
public interface Palette<T> {
|
||||
int idFor(T paramT);
|
||||
|
||||
boolean maybeHas(Predicate<T> paramPredicate);
|
||||
|
||||
T valueFor(int paramInt);
|
||||
|
||||
int getSize();
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
package com.volmit.iris.util.data.palette;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.math.M;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
@@ -64,8 +66,11 @@ public class PalettedContainer<T> implements PaletteResize<T> {
|
||||
for (int var4 = 0; var4 < var2.getSize(); var4++) {
|
||||
T var5 = var3.valueFor(var2.get(var4));
|
||||
if (var5 != null)
|
||||
{
|
||||
set(var4, var5);
|
||||
}
|
||||
}
|
||||
|
||||
return this.palette.idFor(var1);
|
||||
}
|
||||
|
||||
@@ -89,6 +94,12 @@ public class PalettedContainer<T> implements PaletteResize<T> {
|
||||
|
||||
private void set(int var0, T var1) {
|
||||
int var2 = this.palette.idFor(var1);
|
||||
|
||||
if(M.r(0.003))
|
||||
{
|
||||
Iris.info("ID for " + var1 + " is " + var2 + " Palette: " + palette.getSize());
|
||||
}
|
||||
|
||||
this.storage.set(var0, var2);
|
||||
}
|
||||
|
||||
@@ -143,10 +154,6 @@ public class PalettedContainer<T> implements PaletteResize<T> {
|
||||
return var9.getRaw();
|
||||
}
|
||||
|
||||
public boolean maybeHas(Predicate<T> var0) {
|
||||
return this.palette.maybeHas(var0);
|
||||
}
|
||||
|
||||
public void count(CountConsumer<T> var0) {
|
||||
Int2IntOpenHashMap int2IntOpenHashMap = new Int2IntOpenHashMap();
|
||||
this.storage.getAll(var1 -> int2IntOpenHashMap.put(var1, int2IntOpenHashMap.get(var1) + 1));
|
||||
|
||||
Reference in New Issue
Block a user