New additions improvements.
-Added: FlagObject which is a locked version of FlagHandler -Added: UUID support for IListTag -Added: Quaternion now can be turned into a array. -Improved: Using Optimized List functions for Pools.
This commit is contained in:
parent
161d2a1022
commit
8257209337
|
@ -66,5 +66,5 @@ dependencies {
|
|||
compile 'com.google.code.gson:gson:2.8.6'
|
||||
|
||||
//Primitive Collections
|
||||
compile 'de.speiger:Primitive-Collections:0.4.3'
|
||||
compile 'de.speiger:Primitive-Collections:0.4.4'
|
||||
}
|
|
@ -34,6 +34,7 @@ public interface Quaternion
|
|||
public float getY();
|
||||
public float getZ();
|
||||
public float getW();
|
||||
public default float[] asArray(){return new float[]{getX(), getY(), getZ(), getW()};}
|
||||
|
||||
public default Quaternion negate(){return set(0F, 0F, 0F, 0F);}
|
||||
public default Quaternion invert(){return set(-getX(), -getY(), -getZ(), -getW());}
|
||||
|
|
|
@ -28,6 +28,11 @@ public class FlagHolder
|
|||
return true;
|
||||
}
|
||||
|
||||
public void setFlags(int flags)
|
||||
{
|
||||
this.flags = flags;
|
||||
}
|
||||
|
||||
public int getFlags()
|
||||
{
|
||||
return flags;
|
||||
|
@ -43,6 +48,11 @@ public class FlagHolder
|
|||
flags &= ~flag;
|
||||
}
|
||||
|
||||
public void clearFlags()
|
||||
{
|
||||
flags = 0;
|
||||
}
|
||||
|
||||
public boolean isFlagSet(int flag)
|
||||
{
|
||||
return (flags & flag) == flag;
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
package speiger.src.coreengine.utils.collections;
|
||||
|
||||
public class FlagObject
|
||||
{
|
||||
int flags;
|
||||
|
||||
protected FlagObject()
|
||||
{
|
||||
}
|
||||
|
||||
protected void setFlag(int flag)
|
||||
{
|
||||
flags |= flag;
|
||||
}
|
||||
|
||||
protected boolean setFlag(int flag, boolean value)
|
||||
{
|
||||
if(isFlagSet(flag) == value)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
flags = (value ? flags | flag : flags & ~(flag));
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void setFlags(int flags)
|
||||
{
|
||||
this.flags = flags;
|
||||
}
|
||||
|
||||
protected int getFlags()
|
||||
{
|
||||
return flags;
|
||||
}
|
||||
|
||||
protected void flipFlag(int flag)
|
||||
{
|
||||
flags ^= flag;
|
||||
}
|
||||
|
||||
protected void clearFlag(int flag)
|
||||
{
|
||||
flags &= ~flag;
|
||||
}
|
||||
|
||||
protected void clearFlags()
|
||||
{
|
||||
flags = 0;
|
||||
}
|
||||
|
||||
protected boolean isFlagSet(int flag)
|
||||
{
|
||||
return (flags & flag) == flag;
|
||||
}
|
||||
|
||||
protected boolean isAnyFlagSet(int flag)
|
||||
{
|
||||
return (flags & flag) != 0;
|
||||
}
|
||||
|
||||
protected boolean isFlagNotSet(int flag)
|
||||
{
|
||||
return (flags & flag) == 0;
|
||||
}
|
||||
}
|
|
@ -2,17 +2,17 @@ package speiger.src.coreengine.utils.collections.pools;
|
|||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import speiger.src.collections.objects.lists.ObjectArrayList;
|
||||
import speiger.src.collections.objects.lists.ObjectList;
|
||||
import speiger.src.coreengine.utils.functions.Functions;
|
||||
|
||||
public class SimplePool<T> implements IPool<T>
|
||||
{
|
||||
int cap;
|
||||
List<T> stack;
|
||||
ObjectList<T> stack;
|
||||
Supplier<T> creator;
|
||||
Consumer<T> acceptor;
|
||||
|
||||
|
@ -58,11 +58,8 @@ public class SimplePool<T> implements IPool<T>
|
|||
@Override
|
||||
public void accept(T[] array)
|
||||
{
|
||||
for(int i = 0,m=Math.min(array.length, cap - stack.size());i<m;i++)
|
||||
{
|
||||
stack.add(array[i]);
|
||||
acceptor.accept(array[i]);
|
||||
}
|
||||
stack.addAll(array, 0, Math.min(array.length, cap - stack.size()));
|
||||
for(int i = 0,m=Math.min(array.length, cap - stack.size());i<m;acceptor.accept(array[i++]));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -76,4 +73,4 @@ public class SimplePool<T> implements IPool<T>
|
|||
acceptor.accept(next);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,11 +7,12 @@ import java.util.function.Consumer;
|
|||
import java.util.function.Supplier;
|
||||
|
||||
import speiger.src.collections.objects.lists.ObjectArrayList;
|
||||
import speiger.src.collections.objects.lists.ObjectList;
|
||||
import speiger.src.coreengine.utils.functions.Functions;
|
||||
|
||||
public class ThreadLocalPool<T> implements IPool<T>
|
||||
{
|
||||
ThreadLocal<List<T>> stack = ThreadLocal.withInitial(ObjectArrayList::new);
|
||||
ThreadLocal<ObjectList<T>> stack = ThreadLocal.withInitial(ObjectArrayList::new);
|
||||
int cap;
|
||||
Supplier<T> creator;
|
||||
Consumer<T> acceptor;
|
||||
|
@ -58,12 +59,9 @@ public class ThreadLocalPool<T> implements IPool<T>
|
|||
@Override
|
||||
public void accept(T[] array)
|
||||
{
|
||||
List<T> list = stack.get();
|
||||
for(int i = 0,m=Math.min(array.length, cap - list.size());i<m;i++)
|
||||
{
|
||||
list.add(array[i]);
|
||||
acceptor.accept(array[i]);
|
||||
}
|
||||
ObjectList<T> list = stack.get();
|
||||
list.addAll(array, 0, Math.min(array.length, cap - list.size()));
|
||||
for(int i = 0,m=Math.min(array.length, cap - list.size());i<m;acceptor.accept(array[i++]));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,17 +2,17 @@ package speiger.src.coreengine.utils.collections.pools;
|
|||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import speiger.src.collections.objects.lists.ObjectArrayList;
|
||||
import speiger.src.collections.objects.lists.ObjectList;
|
||||
import speiger.src.coreengine.utils.functions.Functions;
|
||||
|
||||
public class ThreadPool<T> implements IPool<T>
|
||||
{
|
||||
int cap;
|
||||
List<T> stack;
|
||||
ObjectList<T> stack;
|
||||
Supplier<T> creator;
|
||||
Consumer<T> acceptor;
|
||||
|
||||
|
@ -42,11 +42,8 @@ public class ThreadPool<T> implements IPool<T>
|
|||
@Override
|
||||
public synchronized void accept(T[] array)
|
||||
{
|
||||
for(int i = 0,m=Math.min(array.length, cap - stack.size());i<m;i++)
|
||||
{
|
||||
stack.add(array[i]);
|
||||
acceptor.accept(array[i]);
|
||||
}
|
||||
stack.addAll(array, 0, Math.min(array.length, cap - stack.size()));
|
||||
for(int i = 0,m=Math.min(array.length, cap - stack.size());i<m;acceptor.accept(array[i++]));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,16 +18,16 @@ import speiger.src.coreengine.utils.collections.iterators.ReadOnlyIterator;
|
|||
|
||||
public class SimpleRegistry<T extends IRegistryEntry<T>> implements IRegistry<T>
|
||||
{
|
||||
protected Object2IntMap<AssetLocation> nameToId = new Object2IntLinkedOpenHashMap<AssetLocation>();
|
||||
protected Object2ObjectMap<AssetLocation, T> nameToValue = new Object2ObjectLinkedOpenHashMap<AssetLocation, T>();
|
||||
protected ObjectList<AssetLocation> idsToName = new ObjectArrayList<AssetLocation>();
|
||||
protected Object2IntMap<AssetLocation> nameToId = new Object2IntLinkedOpenHashMap<>();
|
||||
protected Object2ObjectMap<AssetLocation, T> nameToValue = new Object2ObjectLinkedOpenHashMap<>();
|
||||
protected ObjectList<AssetLocation> idsToName = new ObjectArrayList<>();
|
||||
protected BitSet freeIds;
|
||||
protected int capacity;
|
||||
protected int stored;
|
||||
|
||||
boolean frozen = false;
|
||||
Object2IntMap<AssetLocation> missing = new Object2IntLinkedOpenHashMap<AssetLocation>();
|
||||
Object2ObjectMap<AssetLocation, AssetLocation> remaps = new Object2ObjectLinkedOpenHashMap<AssetLocation, AssetLocation>();
|
||||
Object2IntMap<AssetLocation> missing = new Object2IntLinkedOpenHashMap<>();
|
||||
Object2ObjectMap<AssetLocation, AssetLocation> remaps = new Object2ObjectLinkedOpenHashMap<>();
|
||||
|
||||
public SimpleRegistry(int capacity)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package speiger.src.coreengine.utils.io.dataTag.special;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import speiger.src.coreengine.utils.io.dataTag.DataTag;
|
||||
import speiger.src.coreengine.utils.io.dataTag.array.ByteArrayTag;
|
||||
import speiger.src.coreengine.utils.io.dataTag.array.DoubleArrayTag;
|
||||
|
@ -44,6 +46,8 @@ public interface IListTag extends DataTag
|
|||
public default void addDoubleArray(double[] value) {add(new DoubleArrayTag(value));}
|
||||
public default void addStringArray(String[] value) {add(new StringArrayTag(value));}
|
||||
|
||||
public default void addUUID(UUID id) {add(new LongArrayTag(new long[]{id.getMostSignificantBits(), id.getLeastSignificantBits()}));}
|
||||
|
||||
public default byte getByte(int index) {return ((PrimitiveTag)get(index)).asByte();}
|
||||
public default short getShort(int index) {return ((PrimitiveTag)get(index)).asShort();}
|
||||
public default int getMedium(int index) {return ((PrimitiveTag)get(index)).asInt();}
|
||||
|
@ -62,6 +66,12 @@ public interface IListTag extends DataTag
|
|||
public default double[] getDoubleArray(int index) {return ((DoubleArrayTag)get(index)).get();}
|
||||
public default String[] getStringArray(int index) {return ((StringArrayTag)get(index)).get();}
|
||||
|
||||
public default UUID getUUID(int index)
|
||||
{
|
||||
long[] id = getLongArray(index);
|
||||
return new UUID(id[0], id[1]);
|
||||
}
|
||||
|
||||
public default ListTag getList(int index){return (ListTag)get(index);}
|
||||
public default MapTag getMap(int index){return (MapTag)get(index);}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue