diff --git a/.gitignore b/.gitignore
index ff52c61..5f3b378 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,12 @@
*.iws
.idea/
+# Eclipse files
+.settings
+.classpath
+.project
+bin/
+
# MC FILES
.DS_Store
diff --git a/pom.xml b/pom.xml
index f29bfa0..7e9df62 100644
--- a/pom.xml
+++ b/pom.xml
@@ -155,9 +155,9 @@
- net.sf.trove4j
- trove4j
- 3.0.3
+ it.unimi.dsi
+ fastutil
+ 7.2.1
diff --git a/src/main/java/com/zavtech/morpheus/array/ArrayBase.java b/src/main/java/com/zavtech/morpheus/array/ArrayBase.java
index fc24ca6..cfddae3 100644
--- a/src/main/java/com/zavtech/morpheus/array/ArrayBase.java
+++ b/src/main/java/com/zavtech/morpheus/array/ArrayBase.java
@@ -57,6 +57,8 @@
import com.zavtech.morpheus.util.SortAlgorithm;
import com.zavtech.morpheus.util.functions.ToBooleanFunction;
+import it.unimi.dsi.fastutil.Arrays;
+
/**
* A convenience base class used to build Morpheus Array implementations
*
@@ -184,7 +186,7 @@ public Array fill(T value) {
@Override()
public Array distinct() {
- return distinct(Integer.MAX_VALUE);
+ return distinct(Arrays.MAX_ARRAY_SIZE);
}
@@ -196,7 +198,7 @@ public Array distinct(int limit) {
case LONG: return (Array)ArrayUtils.distinct(stream().longs(), limit);
case DOUBLE: return (Array)ArrayUtils.distinct(stream().doubles(), limit);
default:
- final int capacity = limit < Integer.MAX_VALUE ? limit : 16;
+ final int capacity = limit < it.unimi.dsi.fastutil.Arrays.MAX_ARRAY_SIZE ? limit : 1000;
final Set set = new HashSet<>(capacity);
final ArrayBuilder builder = ArrayBuilder.of(capacity, type());
for (int i=0; i Array toArray(Iterable values) {
* @return the array of distinct values in the order they were observed
*/
public static Array distinct(IntStream values, int limit) {
- final DistinctInts distinct = new DistinctInts(limit);
+ final int capacity = limit < it.unimi.dsi.fastutil.Arrays.MAX_ARRAY_SIZE ? limit : 1000;
+ final DistinctInts distinct = new DistinctInts(limit, capacity);
final PrimitiveIterator.OfInt iterator = values.iterator();
while (iterator.hasNext()) {
final int value = iterator.next();
@@ -134,7 +135,8 @@ public static Array distinct(IntStream values, int limit) {
* @return the array of distinct values in the order they were observed
*/
public static Array distinct(LongStream values, int limit) {
- final DistinctLongs distinct = new DistinctLongs(limit);
+ final int capacity = limit < it.unimi.dsi.fastutil.Arrays.MAX_ARRAY_SIZE ? limit : 1000;
+ final DistinctLongs distinct = new DistinctLongs(limit, capacity);
final PrimitiveIterator.OfLong iterator = values.iterator();
while (iterator.hasNext()) {
final long value = iterator.next();
@@ -154,7 +156,8 @@ public static Array distinct(LongStream values, int limit) {
* @return the array of distinct values in the order they were observed
*/
public static Array distinct(DoubleStream values, int limit) {
- final DistinctDoubles distinct = new DistinctDoubles(limit);
+ final int capacity = limit < it.unimi.dsi.fastutil.Arrays.MAX_ARRAY_SIZE ? limit : 1000;
+ final DistinctDoubles distinct = new DistinctDoubles(limit, capacity);
final PrimitiveIterator.OfDouble iterator = values.iterator();
while (iterator.hasNext()) {
final double value = iterator.next();
@@ -174,7 +177,8 @@ public static Array distinct(DoubleStream values, int limit) {
* @return the array of distinct values in the order they were observed
*/
public static Array distinct(Stream values, int limit) {
- final DistinctValues distinct = new DistinctValues<>(limit);
+ final int capacity = limit < it.unimi.dsi.fastutil.Arrays.MAX_ARRAY_SIZE ? limit : 1000;
+ final DistinctValues distinct = new DistinctValues<>(limit, capacity);
final Iterator iterator = values.iterator();
while (iterator.hasNext()) {
final V value = iterator.next();
@@ -198,10 +202,10 @@ private static class DistinctCalculator {
/**
* Constructor
* @param type the data type
- * @param limit the limit
+ * @param capacity the initial capacity for array builder
*/
- DistinctCalculator(Class type, int limit) {
- this.builder = ArrayBuilder.of(limit < Integer.MAX_VALUE ? limit : 1000, type);
+ DistinctCalculator(Class type, int capacity) {
+ this.builder = ArrayBuilder.of(capacity, type);
}
/**
@@ -219,16 +223,17 @@ public final Array toArray() {
private static class DistinctInts extends DistinctCalculator {
private int limit;
- private TIntSet distinctSet;
+ private IntSet distinctSet;
/**
* Constructor
* @param limit the limit for this calculator
+ * @param capacity the initial capacity for set
*/
- DistinctInts(int limit) {
- super(Integer.class, limit);
+ DistinctInts(int limit, int capacity) {
+ super(Integer.class, capacity);
this.limit = limit;
- this.distinctSet = new TIntHashSet(limit < Integer.MAX_VALUE ? limit : 1000);
+ this.distinctSet = new IntOpenHashSet(capacity);
}
/**
@@ -250,16 +255,16 @@ public final boolean add(int value) {
private static class DistinctLongs extends DistinctCalculator {
private int limit;
- private TLongSet distinctSet;
+ private LongSet distinctSet;
/**
* Constructor
* @param limit the limit for this calculator
*/
- DistinctLongs(int limit) {
- super(Long.class, limit);
+ DistinctLongs(int limit, int capacity) {
+ super(Long.class, capacity);
this.limit = limit;
- this.distinctSet = new TLongHashSet(limit < Integer.MAX_VALUE ? limit : 1000);
+ this.distinctSet = new LongOpenHashSet(capacity);
}
/**
@@ -280,16 +285,16 @@ public final boolean add(long value) {
private static class DistinctDoubles extends DistinctCalculator {
private int limit;
- private TDoubleSet distinctSet;
+ private DoubleSet distinctSet;
/**
* Constructor
* @param limit the limit for this calculator
*/
- DistinctDoubles(int limit) {
- super(Double.class, limit);
+ DistinctDoubles(int limit, int capacity) {
+ super(Double.class, capacity);
this.limit = limit;
- this.distinctSet = new TDoubleHashSet(limit < Integer.MAX_VALUE ? limit : 1000);
+ this.distinctSet = new DoubleOpenHashSet(capacity);
}
/**
@@ -317,10 +322,10 @@ private static class DistinctValues extends DistinctCalculator {
* @param limit the limit for this calculator
*/
@SuppressWarnings("unchecked")
- DistinctValues(int limit) {
- super((Class)Object.class, limit);
+ DistinctValues(int limit, int capacity) {
+ super((Class)Object.class, capacity);
this.limit = limit;
- this.distinctSet = new HashSet<>(limit < Integer.MAX_VALUE ? limit : 1000);
+ this.distinctSet = new HashSet<>(capacity);
}
/**
diff --git a/src/main/java/com/zavtech/morpheus/array/coding/IntCoding.java b/src/main/java/com/zavtech/morpheus/array/coding/IntCoding.java
index 508c936..4d7368f 100644
--- a/src/main/java/com/zavtech/morpheus/array/coding/IntCoding.java
+++ b/src/main/java/com/zavtech/morpheus/array/coding/IntCoding.java
@@ -22,12 +22,12 @@
import java.util.TimeZone;
import java.util.stream.IntStream;
-import gnu.trove.map.TObjectIntMap;
-import gnu.trove.map.hash.TObjectIntHashMap;
-
import com.zavtech.morpheus.util.IntComparator;
import com.zavtech.morpheus.util.SortAlgorithm;
+import it.unimi.dsi.fastutil.objects.Object2IntMap;
+import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
+
/**
* An interface that exposes a coding between object values and corresponding int code
*
@@ -169,7 +169,7 @@ class OfCurrency extends BaseCoding implements IntCoding {
private static final long serialVersionUID = 1L;
private final Currency[] currencies;
- private final TObjectIntMap codeMap;
+ private final Object2IntMap codeMap;
/**
* Constructor
@@ -177,7 +177,8 @@ class OfCurrency extends BaseCoding implements IntCoding {
public OfCurrency() {
super(Currency.class);
this.currencies = Currency.getAvailableCurrencies().stream().toArray(Currency[]::new);
- this.codeMap = new TObjectIntHashMap<>(currencies.length, 0.5f, -1);
+ this.codeMap = new Object2IntOpenHashMap<>(currencies.length, 0.5f);
+ this.codeMap.defaultReturnValue(-1);
Arrays.sort(currencies, (c1, c2) -> c1.getCurrencyCode().compareTo(c2.getCurrencyCode()));
for (int i = 0; i< currencies.length; ++i) {
this.codeMap.put(currencies[i], i);
@@ -186,7 +187,7 @@ public OfCurrency() {
@Override
public final int getCode(Currency value) {
- return value == null ? -1 : codeMap.get(value);
+ return value == null ? -1 : codeMap.getInt(value);
}
@Override
@@ -204,7 +205,7 @@ class OfZoneId extends BaseCoding implements IntCoding {
private static final long serialVersionUID = 1L;
private final ZoneId[] zoneIds;
- private final TObjectIntMap codeMap;
+ private final Object2IntMap codeMap;
/**
* Constructor
@@ -212,7 +213,8 @@ class OfZoneId extends BaseCoding implements IntCoding {
OfZoneId() {
super(ZoneId.class);
this.zoneIds = ZoneId.getAvailableZoneIds().stream().map(ZoneId::of).toArray(ZoneId[]::new);
- this.codeMap = new TObjectIntHashMap<>(zoneIds.length, 0.5f, -1);
+ this.codeMap = new Object2IntOpenHashMap<>(zoneIds.length, 0.5f);
+ this.codeMap.defaultReturnValue(-1);
Arrays.sort(zoneIds, (z1, z2) -> z1.getId().compareTo(z2.getId()));
for (int i=0; i implements IntCoding {
@Override
public final int getCode(ZoneId value) {
- return value == null ? -1 : codeMap.get(value);
+ return value == null ? -1 : codeMap.getInt(value);
}
@Override
@@ -239,7 +241,7 @@ class OfTimeZone extends BaseCoding implements IntCoding {
private static final long serialVersionUID = 1L;
private final TimeZone[] timeZones;
- private final TObjectIntMap codeMap;
+ private final Object2IntMap codeMap;
/**
* Constructor
@@ -247,7 +249,8 @@ class OfTimeZone extends BaseCoding implements IntCoding {
OfTimeZone() {
super(TimeZone.class);
this.timeZones = Arrays.stream(TimeZone.getAvailableIDs()).map(TimeZone::getTimeZone).toArray(TimeZone[]::new);
- this.codeMap = new TObjectIntHashMap<>(timeZones.length, 0.5f, -1);
+ this.codeMap = new Object2IntOpenHashMap<>(timeZones.length, 0.5f);
+ this.codeMap.defaultReturnValue(-1);
Arrays.sort(timeZones, (tz1, tz2) -> tz1.getID().compareTo(tz2.getID()));
for (int i = 0; i< timeZones.length; ++i) {
this.codeMap.put(timeZones[i], i);
@@ -256,7 +259,7 @@ class OfTimeZone extends BaseCoding implements IntCoding {
@Override
public final int getCode(TimeZone value) {
- return value == null ? -1 : codeMap.get(value);
+ return value == null ? -1 : codeMap.getInt(value);
}
@Override
diff --git a/src/main/java/com/zavtech/morpheus/array/dense/DenseArrayOfBooleans.java b/src/main/java/com/zavtech/morpheus/array/dense/DenseArrayOfBooleans.java
index 6f09991..848f121 100644
--- a/src/main/java/com/zavtech/morpheus/array/dense/DenseArrayOfBooleans.java
+++ b/src/main/java/com/zavtech/morpheus/array/dense/DenseArrayOfBooleans.java
@@ -21,17 +21,17 @@
import java.util.Arrays;
import java.util.function.Predicate;
-import gnu.trove.set.TShortSet;
-import gnu.trove.set.hash.TShortHashSet;
-
+import com.zavtech.morpheus.array.Array;
+import com.zavtech.morpheus.array.ArrayBase;
import com.zavtech.morpheus.array.ArrayBuilder;
import com.zavtech.morpheus.array.ArrayCursor;
import com.zavtech.morpheus.array.ArrayException;
-import com.zavtech.morpheus.array.Array;
-import com.zavtech.morpheus.array.ArrayBase;
import com.zavtech.morpheus.array.ArrayStyle;
import com.zavtech.morpheus.array.ArrayValue;
+import it.unimi.dsi.fastutil.shorts.ShortOpenHashSet;
+import it.unimi.dsi.fastutil.shorts.ShortSet;
+
/**
* An Array implementation designed to hold a dense array of boolean values
*
@@ -281,7 +281,8 @@ public int binarySearch(int start, int end, Boolean value) {
@Override
public Array distinct(int limit) {
- final TShortSet set = new TShortHashSet(limit);
+ final int capacity = limit < it.unimi.dsi.fastutil.Arrays.MAX_ARRAY_SIZE ? limit : 1000;
+ final ShortSet set = new ShortOpenHashSet(capacity);
final ArrayBuilder builder = ArrayBuilder.of(2, Boolean.class);
for (int i=0; i distinct(int limit) {
- final int capacity = limit < Integer.MAX_VALUE ? limit : 100;
- final TDoubleSet set = new TDoubleHashSet(capacity);
+ final int capacity = limit < it.unimi.dsi.fastutil.Arrays.MAX_ARRAY_SIZE ? limit : 1000;
+ final DoubleSet set = new DoubleOpenHashSet(capacity);
final ArrayBuilder builder = ArrayBuilder.of(capacity, Double.class);
for (int i=0; i distinct(int limit) {
- final int capacity = limit < Integer.MAX_VALUE ? limit : 100;
- final TIntSet set = new TIntHashSet(capacity);
+ final int capacity = limit < it.unimi.dsi.fastutil.Arrays.MAX_ARRAY_SIZE ? limit : 100;
+ final IntSet set = new IntOpenHashSet(capacity);
final ArrayBuilder builder = ArrayBuilder.of(capacity, Integer.class);
for (int i=0; i distinct(int limit) {
- final int capacity = limit < Integer.MAX_VALUE ? limit : 100;
- final TLongSet set = new TLongHashSet(capacity);
+ final int capacity = limit < it.unimi.dsi.fastutil.Arrays.MAX_ARRAY_SIZE ? limit : 1000;
+ final LongSet set = new LongOpenHashSet(capacity);
final ArrayBuilder builder = ArrayBuilder.of(capacity, Long.class);
for (int i=0; i distinct(int limit) {
- final int capacity = limit < Integer.MAX_VALUE ? limit : 100;
- final TIntSet set = new TIntHashSet(capacity);
+ final int capacity = limit < it.unimi.dsi.fastutil.Arrays.MAX_ARRAY_SIZE ? limit : 1000;
+ final IntSet set = new IntOpenHashSet(capacity);
final ArrayBuilder builder = ArrayBuilder.of(capacity, type());
for (int i=0; i distinct(int limit) {
- final int capacity = limit < Integer.MAX_VALUE ? limit : 100;
- final TLongSet set = new TLongHashSet(capacity);
+ final int capacity = limit < it.unimi.dsi.fastutil.Arrays.MAX_ARRAY_SIZE ? limit : 1000;
+ final LongSet set = new LongOpenHashSet(capacity);
final ArrayBuilder builder = ArrayBuilder.of(capacity, type());
for (int i=0; i distinct(int limit) {
- final TShortSet set = new TShortHashSet(limit);
+ final int capacity = limit < it.unimi.dsi.fastutil.Arrays.MAX_ARRAY_SIZE ? limit : 1000;
+ final ShortSet set = new ShortOpenHashSet(capacity);
final ArrayBuilder builder = ArrayBuilder.of(2, Boolean.class);
for (int i=0; i distinct(int limit) {
- final int capacity = limit < Integer.MAX_VALUE ? limit : 100;
- final TDoubleSet set = new TDoubleHashSet(capacity);
+ final int capacity = limit < it.unimi.dsi.fastutil.Arrays.MAX_ARRAY_SIZE ? limit : 1000;
+ final DoubleSet set = new DoubleOpenHashSet(capacity);
final ArrayBuilder builder = ArrayBuilder.of(capacity, Double.class);
for (int i=0; i distinct(int limit) {
- final int capacity = limit < Integer.MAX_VALUE ? limit : 100;
- final TIntSet set = new TIntHashSet(capacity);
+ final int capacity = limit < it.unimi.dsi.fastutil.Arrays.MAX_ARRAY_SIZE ? limit : 1000;
+ final IntSet set = new IntOpenHashSet(capacity);
final ArrayBuilder builder = ArrayBuilder.of(capacity, Integer.class);
for (int i=0; i distinct(int limit) {
- final int capacity = limit < Integer.MAX_VALUE ? limit : 100;
- final TLongSet set = new TLongHashSet(capacity);
+ final int capacity = limit < it.unimi.dsi.fastutil.Arrays.MAX_ARRAY_SIZE ? limit : 1000;
+ final LongSet set = new LongOpenHashSet(capacity);
final ArrayBuilder builder = ArrayBuilder.of(capacity, Long.class);
for (int i=0; i distinct(int limit) {
- final int capacity = limit < Integer.MAX_VALUE ? limit : 100;
- final TIntSet set = new TIntHashSet(capacity);
+ final int capacity = limit < it.unimi.dsi.fastutil.Arrays.MAX_ARRAY_SIZE ? limit : 1000;
+ final IntSet set = new IntOpenHashSet(capacity);
final ArrayBuilder builder = ArrayBuilder.of(capacity, type());
for (int i=0; i distinct(int limit) {
- final int capacity = limit < Integer.MAX_VALUE ? limit : 100;
- final TLongSet set = new TLongHashSet(capacity);
+ final int capacity = limit < it.unimi.dsi.fastutil.Arrays.MAX_ARRAY_SIZE ? limit : 1000;
+ final LongSet set = new LongOpenHashSet(capacity);
final ArrayBuilder builder = ArrayBuilder.of(capacity, type());
for (int i=0; i {
private static final long serialVersionUID = 1L;
private int length;
- private TIntDoubleMap values;
+ private Int2DoubleMap values;
private double defaultValue;
/**
@@ -57,7 +57,8 @@ class SparseArrayOfDoubles extends ArrayBase {
super(Double.class, ArrayStyle.SPARSE, false);
this.length = length;
this.defaultValue = defaultValue != null ? defaultValue : Double.NaN;
- this.values = new TIntDoubleHashMap((int)Math.max(length * 0.5, 10d), 0.8f, -1, this.defaultValue);
+ this.values = new Int2DoubleOpenHashMap((int)Math.max(length * 0.5, 10d), 0.8f);
+ this.values.defaultReturnValue(this.defaultValue);
}
/**
@@ -107,7 +108,7 @@ public final Array sequential() {
public final Array copy() {
try {
final SparseArrayOfDoubles copy = (SparseArrayOfDoubles)super.clone();
- copy.values = new TIntDoubleHashMap(values);
+ copy.values = new Int2DoubleOpenHashMap(values);
copy.defaultValue = this.defaultValue;
return copy;
} catch (Exception ex) {
@@ -277,7 +278,7 @@ public final Double setValue(int index, Double value) {
this.values.remove(index);
return oldValue;
} else {
- this.values.put(index, value);
+ this.values.put(index, (double) value);
return oldValue;
}
}
@@ -305,8 +306,8 @@ public final int binarySearch(int start, int end, Double value) {
@Override
public final Array distinct(int limit) {
- final int capacity = limit < Integer.MAX_VALUE ? limit : 100;
- final TDoubleSet set = new TDoubleHashSet(capacity);
+ final int capacity = limit < it.unimi.dsi.fastutil.Arrays.MAX_ARRAY_SIZE ? limit : 1000;
+ final DoubleSet set = new DoubleOpenHashSet(capacity);
final ArrayBuilder builder = ArrayBuilder.of(capacity, Double.class);
for (int i=0; i {
private static final long serialVersionUID = 1L;
private int length;
- private TIntIntMap values;
+ private Int2IntMap values;
private int defaultValue;
/**
@@ -57,7 +57,8 @@ class SparseArrayOfInts extends ArrayBase {
super(Integer.class, ArrayStyle.SPARSE, false);
this.length = length;
this.defaultValue = defaultValue != null ? defaultValue : 0;
- this.values = new TIntIntHashMap((int)Math.max(length * 0.5, 10d), 0.8f, -1, this.defaultValue);
+ this.values = new Int2IntOpenHashMap((int)Math.max(length * 0.5, 10d), 0.8f);
+ this.values.defaultReturnValue(this.defaultValue);
}
/**
@@ -107,7 +108,7 @@ public final Array sequential() {
public final Array copy() {
try {
final SparseArrayOfInts copy = (SparseArrayOfInts)super.clone();
- copy.values = new TIntIntHashMap(values);
+ copy.values = new Int2IntOpenHashMap(values);
copy.defaultValue = this.defaultValue;
return copy;
} catch (Exception ex) {
@@ -288,7 +289,7 @@ public final Integer setValue(int index, Integer value) {
this.values.remove(index);
return oldValue;
} else {
- this.values.put(index, value);
+ this.values.put((int) index, (int) value);
return oldValue;
}
}
@@ -316,8 +317,8 @@ public final int binarySearch(int start, int end, Integer value) {
@Override
public final Array distinct(int limit) {
- final int capacity = limit < Integer.MAX_VALUE ? limit : 100;
- final TIntSet set = new TIntHashSet(capacity);
+ final int capacity = limit < it.unimi.dsi.fastutil.Arrays.MAX_ARRAY_SIZE ? limit : 1000;
+ final IntSet set = new IntOpenHashSet(capacity);
final ArrayBuilder builder = ArrayBuilder.of(capacity, Integer.class);
for (int i=0; i {
private static final long serialVersionUID = 1L;
private int length;
- private TIntLongMap values;
+ private Int2LongMap values;
private long defaultValue;
/**
@@ -57,7 +57,8 @@ class SparseArrayOfLongs extends ArrayBase {
super(Long.class, ArrayStyle.SPARSE, false);
this.length = length;
this.defaultValue = defaultValue != null ? defaultValue : 0L;
- this.values = new TIntLongHashMap((int)Math.max(length * 0.5, 10d), 0.8f, -1, this.defaultValue);
+ this.values = new Int2LongOpenHashMap((int)Math.max(length * 0.5, 10d), 0.8f);
+ this.values.defaultReturnValue(this.defaultValue);
}
/**
@@ -107,7 +108,7 @@ public final Array sequential() {
public final Array copy() {
try {
final SparseArrayOfLongs copy = (SparseArrayOfLongs)super.clone();
- copy.values = new TIntLongHashMap(values);
+ copy.values = new Int2LongOpenHashMap(values);
copy.defaultValue = this.defaultValue;
return copy;
} catch (Exception ex) {
@@ -284,7 +285,7 @@ public final Long setValue(int index, Long value) {
this.values.remove(index);
return oldValue;
} else {
- this.values.put(index,value);
+ this.values.put(index, (long) value);
return oldValue;
}
}
@@ -312,8 +313,8 @@ public final int binarySearch(int start, int end, Long value) {
@Override
public final Array distinct(int limit) {
- final int capacity = limit < Integer.MAX_VALUE ? limit : 100;
- final TLongSet set = new TLongHashSet(capacity);
+ final int capacity = limit < it.unimi.dsi.fastutil.Arrays.MAX_ARRAY_SIZE ? limit : 1000;
+ final LongSet set = new LongOpenHashSet(capacity);
final ArrayBuilder builder = ArrayBuilder.of(capacity, Long.class);
for (int i=0; i extends ArrayBase {
private int length;
private T defaultValue;
- private TIntObjectMap