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 values; + private Int2ObjectMap values; /** * Constructor @@ -55,7 +55,7 @@ class SparseArrayOfObjects extends ArrayBase { super(type, ArrayStyle.SPARSE, false); this.length = length; this.defaultValue = defaultValue; - this.values = new TIntObjectHashMap<>((int)Math.max(length * 0.5, 10d), 0.8f, -1); + this.values = new Int2ObjectOpenHashMap<>((int)Math.max(length * 0.5, 10d)); } /** @@ -68,6 +68,7 @@ private SparseArrayOfObjects(SparseArrayOfObjects source, boolean parallel) { this.length = source.length; this.defaultValue = source.defaultValue; this.values = source.values; + this.values.defaultReturnValue(this.defaultValue); } @@ -105,7 +106,7 @@ public final Array sequential() { public final Array copy() { try { final SparseArrayOfObjects copy = (SparseArrayOfObjects)super.clone(); - copy.values = new TIntObjectHashMap<>(values); + copy.values = new Int2ObjectOpenHashMap<>(values); copy.defaultValue = this.defaultValue; return copy; } catch (Exception ex) { diff --git a/src/main/java/com/zavtech/morpheus/array/sparse/SparseArrayOfZonedDateTimes.java b/src/main/java/com/zavtech/morpheus/array/sparse/SparseArrayOfZonedDateTimes.java index f2b1597..8e43983 100644 --- a/src/main/java/com/zavtech/morpheus/array/sparse/SparseArrayOfZonedDateTimes.java +++ b/src/main/java/com/zavtech/morpheus/array/sparse/SparseArrayOfZonedDateTimes.java @@ -25,11 +25,6 @@ import java.util.Map; import java.util.function.Predicate; -import gnu.trove.map.TIntLongMap; -import gnu.trove.map.TIntShortMap; -import gnu.trove.map.hash.TIntLongHashMap; -import gnu.trove.map.hash.TIntShortHashMap; - import com.zavtech.morpheus.array.Array; import com.zavtech.morpheus.array.ArrayBase; import com.zavtech.morpheus.array.ArrayCursor; @@ -37,6 +32,11 @@ import com.zavtech.morpheus.array.ArrayStyle; import com.zavtech.morpheus.array.ArrayValue; +import it.unimi.dsi.fastutil.ints.Int2LongMap; +import it.unimi.dsi.fastutil.ints.Int2LongOpenHashMap; +import it.unimi.dsi.fastutil.ints.Int2ShortMap; +import it.unimi.dsi.fastutil.ints.Int2ShortOpenHashMap; + /** * An Array implementation containing a sparse array of LocalDateTine values stored as a long of epoch milliseconds. * @@ -69,8 +69,8 @@ class SparseArrayOfZonedDateTimes extends ArrayBase { private static final short UTC_ZONE = zoneIdMap1.get(ZoneId.of("UTC")); private int length; - private TIntLongMap values; - private TIntShortMap zoneIds; + private Int2LongMap values; + private Int2ShortMap zoneIds; private ZonedDateTime defaultValue; private final short defaultZoneId; private long defaultValueAsLong; @@ -85,8 +85,10 @@ class SparseArrayOfZonedDateTimes extends ArrayBase { this.defaultValue = defaultValue; this.defaultValueAsLong = defaultValue != null ? defaultValue.toInstant().toEpochMilli() : nullValue; this.defaultZoneId = defaultValue != null ? zoneIdMap1.get(defaultValue.getZone()) : NULL_ZONE; - this.values = new TIntLongHashMap((int)Math.max(length * 0.5, 10d), 0.8f, -1, defaultValueAsLong); - this.zoneIds = new TIntShortHashMap((int)Math.max(length * 0.5, 10d), 0.8f, -1, defaultZoneId); + this.values = new Int2LongOpenHashMap((int)Math.max(length * 0.5, 10d), 0.8f); + this.values.defaultReturnValue(this.defaultValueAsLong); + this.zoneIds = new Int2ShortOpenHashMap((int)Math.max(length * 0.5, 10d), 0.8f); + this.zoneIds.defaultReturnValue(this.defaultZoneId); } /** @@ -138,8 +140,8 @@ public final Array sequential() { public final Array copy() { try { final SparseArrayOfZonedDateTimes copy = (SparseArrayOfZonedDateTimes)super.clone(); - copy.values = new TIntLongHashMap(values); - copy.zoneIds = new TIntShortHashMap(zoneIds); + copy.values = new Int2LongOpenHashMap(values); + copy.zoneIds = new Int2ShortOpenHashMap(zoneIds); copy.defaultValue = this.defaultValue; copy.defaultValueAsLong = this.defaultValueAsLong; return copy; diff --git a/src/main/java/com/zavtech/morpheus/array/sparse/SparseArrayWithIntCoding.java b/src/main/java/com/zavtech/morpheus/array/sparse/SparseArrayWithIntCoding.java index 25cc2f4..1141df9 100644 --- a/src/main/java/com/zavtech/morpheus/array/sparse/SparseArrayWithIntCoding.java +++ b/src/main/java/com/zavtech/morpheus/array/sparse/SparseArrayWithIntCoding.java @@ -20,11 +20,6 @@ import java.io.ObjectOutputStream; import java.util.function.Predicate; -import gnu.trove.map.TIntIntMap; -import gnu.trove.map.hash.TIntIntHashMap; -import gnu.trove.set.TIntSet; -import gnu.trove.set.hash.TIntHashSet; - import com.zavtech.morpheus.array.Array; import com.zavtech.morpheus.array.ArrayBase; import com.zavtech.morpheus.array.ArrayBuilder; @@ -34,6 +29,11 @@ import com.zavtech.morpheus.array.ArrayValue; import com.zavtech.morpheus.array.coding.IntCoding; +import it.unimi.dsi.fastutil.ints.Int2IntMap; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; +import it.unimi.dsi.fastutil.ints.IntOpenHashSet; +import it.unimi.dsi.fastutil.ints.IntSet; + /** * A sparse array implementation that maintains a primitive int array of codes that apply to Object values exposed through the Coding interface. * @@ -48,7 +48,7 @@ class SparseArrayWithIntCoding extends ArrayBase { private int length; private T defaultValue; private int defaultCode; - private TIntIntMap codes; + private Int2IntMap codes; private IntCoding coding; @@ -64,7 +64,8 @@ class SparseArrayWithIntCoding extends ArrayBase { this.coding = coding; this.defaultValue = defaultValue; this.defaultCode = coding.getCode(defaultValue); - this.codes = new TIntIntHashMap((int)Math.max(length * 0.5, 10d), 0.8f, -1, defaultCode); + this.codes = new Int2IntOpenHashMap((int)Math.max(length * 0.5, 10d), 0.8f); + this.codes.defaultReturnValue(this.defaultCode); } /** @@ -116,7 +117,7 @@ public final Array sequential() { public final Array copy() { try { final SparseArrayWithIntCoding copy = (SparseArrayWithIntCoding)super.clone(); - copy.codes = new TIntIntHashMap(codes); + copy.codes = new Int2IntOpenHashMap(codes); copy.defaultValue = this.defaultValue; copy.defaultCode = this.defaultCode; copy.coding = this.coding; @@ -286,8 +287,8 @@ public final T setValue(int index, T value) { @Override public 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, type()); for (int i=0; i extends ArrayBase { private int length; private T defaultValue; private long defaultCode; - private TIntLongMap codes; + private Int2LongMap codes; private LongCoding coding; @@ -64,7 +64,8 @@ class SparseArrayWithLongCoding extends ArrayBase { this.coding = coding; this.defaultValue = defaultValue; this.defaultCode = coding.getCode(defaultValue); - this.codes = new TIntLongHashMap((int)Math.max(length * 0.5, 10d), 0.8f, -1, defaultCode); + this.codes = new Int2LongOpenHashMap((int)Math.max(length * 0.5, 10d), 0.8f); + this.codes.defaultReturnValue(this.defaultCode); } /** @@ -117,7 +118,7 @@ public final Array sequential() { public final Array copy() { try { final SparseArrayWithLongCoding copy = (SparseArrayWithLongCoding)super.clone(); - copy.codes = new TIntLongHashMap(codes); + copy.codes = new Int2LongOpenHashMap(codes); copy.defaultValue = this.defaultValue; copy.defaultCode = this.defaultCode; copy.coding = this.coding; @@ -297,8 +298,8 @@ public final T setValue(int index, T value) { @Override public 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, type()); for (int i=0; i { private static final long serialVersionUID = 1L; - private TDoubleIntMap indexMap; + private Double2IntMap indexMap; /** * Constructor @@ -41,7 +42,8 @@ class IndexOfDoubles extends IndexBase { */ IndexOfDoubles(int initialSize) { super(Array.of(Double.class, initialSize)); - this.indexMap = new TDoubleIntHashMap(initialSize, 0.75f, -1, -1); + this.indexMap = new Double2IntOpenHashMap(initialSize, 0.75f); + this.indexMap.defaultReturnValue(-1); } /** @@ -50,7 +52,8 @@ class IndexOfDoubles extends IndexBase { */ IndexOfDoubles(Iterable iterable) { super(iterable); - this.indexMap = new TDoubleIntHashMap(keyArray().length(), 0.75f, -1, -1); + this.indexMap = new Double2IntOpenHashMap(keyArray().length(), 0.75f); + this.indexMap.defaultReturnValue(-1); this.keyArray().sequential().forEachValue(v -> { final int index = v.index(); final double key = v.getDouble(); @@ -68,7 +71,8 @@ class IndexOfDoubles extends IndexBase { */ private IndexOfDoubles(Iterable iterable, IndexOfDoubles parent) { super(iterable, parent); - this.indexMap = new TDoubleIntHashMap(keyArray().length(), 0.75f, -1, -1); + this.indexMap = new Double2IntOpenHashMap(keyArray().length(), 0.75f); + this.indexMap.defaultReturnValue(-1); this.keyArray().sequential().forEachValue(v -> { final double key = v.getDouble(); final int index = parent.indexMap.get(key); @@ -110,7 +114,7 @@ public final boolean add(Double key) { final int index = indexMap.size(); this.ensureCapacity(index + 1); this.keyArray().setValue(index, key); - this.indexMap.put(key, index); + this.indexMap.put((double) key, index); return true; } } @@ -143,7 +147,7 @@ public final int addAll(Iterable keys, boolean ignoreDuplicates) { public final Index copy() { try { final IndexOfDoubles clone = (IndexOfDoubles)super.copy(); - clone.indexMap = new TDoubleIntHashMap(indexMap); + clone.indexMap = new Double2IntOpenHashMap(indexMap); return clone; } catch (Exception ex) { throw new IndexException("Failed to clone index", ex); @@ -157,7 +161,7 @@ public final int size() { @Override public final int getIndexForKey(Double key) { - final int index = indexMap.get(key); + final int index = indexMap.get(key.doubleValue()); if (index < 0) { throw new IndexException("No match for key in index: " + key); } else { @@ -172,15 +176,15 @@ public final boolean contains(Double key) { @Override public final int replace(Double existing, Double replacement) { - final int index = indexMap.remove(existing); + final int index = indexMap.remove(existing.doubleValue()); if (index == -1) { throw new IndexException("No match key for " + existing); } else { - if (indexMap.containsKey(replacement)) { + if (indexMap.containsKey(replacement.doubleValue())) { throw new IndexException("The replacement key already exists in index " + replacement); } else { final int ordinal = getOrdinalForIndex(index); - this.indexMap.put(replacement, index); + this.indexMap.put((double) replacement, index); this.keyArray().setValue(ordinal, replacement); return index; } @@ -192,7 +196,7 @@ public final void forEachEntry(IndexConsumer consumer) { final int size = size(); for (int i=0; i { private static final long serialVersionUID = 1L; - private TIntIntMap indexMap; + private Int2IntMap indexMap; /** * Constructor @@ -44,7 +44,8 @@ class IndexOfInts extends IndexBase { */ IndexOfInts(int initialSize) { super(Array.of(Integer.class, initialSize)); - this.indexMap = new TIntIntHashMap(initialSize, 0.75f, -1, -1); + this.indexMap = new Int2IntOpenHashMap(initialSize, 0.75f); + this.indexMap.defaultReturnValue(-1); } /** @@ -54,7 +55,8 @@ class IndexOfInts extends IndexBase { */ IndexOfInts(Iterable iterable) { super(iterable); - this.indexMap = new TIntIntHashMap(keyArray().length(), 0.75f, -1, -1); + this.indexMap = new Int2IntOpenHashMap(keyArray().length(), 0.75f); + this.indexMap.defaultReturnValue(-1); this.keyArray().sequential().forEachValue(v -> { final int index = v.index(); final int key = v.getInt(); @@ -73,7 +75,8 @@ class IndexOfInts extends IndexBase { */ private IndexOfInts(Iterable iterable, IndexOfInts parent) { super(iterable, parent); - this.indexMap = new TIntIntHashMap(keyArray().length(), 0.75f, -1, -1); + this.indexMap = new Int2IntOpenHashMap(keyArray().length(), 0.75f); + this.indexMap.defaultReturnValue(-1); this.keyArray().sequential().forEachValue(v -> { final int key = v.getInt(); final int index = parent.indexMap.get(key); @@ -109,13 +112,13 @@ public final boolean add(Integer key) { if (isFilter()) { throw new IndexException("Cannot add keys to an filter on another index"); } else { - if (indexMap.containsKey(key)) { + if (indexMap.containsKey(key.intValue())) { return false; } else { final int index = indexMap.size(); this.ensureCapacity(index + 1); this.keyArray().setValue(index, key); - this.indexMap.put(key, index); + this.indexMap.put((int) key, index); return true; } } @@ -148,7 +151,7 @@ public int addAll(Iterable keys, boolean ignoreDuplicates) { public final Index copy() { try { final IndexOfInts clone = (IndexOfInts)super.copy(); - clone.indexMap = new TIntIntHashMap(indexMap); + clone.indexMap = new Int2IntOpenHashMap(indexMap); return clone; } catch (Exception ex) { throw new IndexException("Failed to clone index", ex); @@ -162,7 +165,7 @@ public final int size() { @Override public final int getIndexForKey(Integer key) { - final int index = indexMap.get(key); + final int index = indexMap.get(key.intValue()); if (index < 0) { throw new IndexException("No match for key in index: " + key); } else { @@ -172,20 +175,20 @@ public final int getIndexForKey(Integer key) { @Override public final boolean contains(Integer key) { - return indexMap.containsKey(key); + return indexMap.containsKey(key.intValue()); } @Override public final int replace(Integer existing, Integer replacement) { - final int index = indexMap.remove(existing); + final int index = indexMap.remove(existing.intValue()); if (index == -1) { throw new IndexException("No match key for " + existing); } else { - if (indexMap.containsKey(replacement)) { + if (indexMap.containsKey(replacement.intValue())) { throw new IndexException("The replacement key already exists in index " + replacement); } else { final int ordinal = getOrdinalForIndex(index); - this.indexMap.put(replacement, index); + this.indexMap.put((int) replacement, index); this.keyArray().setValue(ordinal, replacement); return index; } @@ -197,7 +200,7 @@ public final void forEachEntry(IndexConsumer consumer) { final int size = size(); for (int i = 0; i < size; ++i) { final Integer key = keyArray().getValue(i); - final int index = indexMap.get(key); + final int index = indexMap.get(key.intValue()); consumer.accept(key, index); } } @@ -206,9 +209,8 @@ public final void forEachEntry(IndexConsumer consumer) { @Override public final Index resetOrder() { final Array keys = keyArray(); - this.indexMap.forEachEntry((key, index) -> { + this.indexMap.forEach((key, index) -> { keys.setInt(index, key); - return true; }); return this; } @@ -219,9 +221,8 @@ public final Index sort(boolean parallel, IntComparator comparator) { super.sort(parallel, comparator); if (comparator == null) { final Array keys = keyArray(); - this.indexMap.forEachEntry((key, index) -> { + this.indexMap.forEach((key, index) -> { keys.setInt(index, key); - return true; }); } return this; diff --git a/src/main/java/com/zavtech/morpheus/index/IndexOfLongs.java b/src/main/java/com/zavtech/morpheus/index/IndexOfLongs.java index 09ea58c..6b27875 100644 --- a/src/main/java/com/zavtech/morpheus/index/IndexOfLongs.java +++ b/src/main/java/com/zavtech/morpheus/index/IndexOfLongs.java @@ -19,8 +19,9 @@ import com.zavtech.morpheus.array.Array; import com.zavtech.morpheus.array.ArrayBuilder; -import gnu.trove.map.TLongIntMap; -import gnu.trove.map.hash.TLongIntHashMap; + +import it.unimi.dsi.fastutil.longs.Long2IntMap; +import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap; /** * An Index implementation designed to efficiently store long values @@ -33,7 +34,7 @@ class IndexOfLongs extends IndexBase { private static final long serialVersionUID = 1L; - private TLongIntMap indexMap; + private Long2IntMap indexMap; /** * Constructor @@ -41,7 +42,8 @@ class IndexOfLongs extends IndexBase { */ IndexOfLongs(int initialSize) { super(Array.of(Long.class, initialSize)); - this.indexMap = new TLongIntHashMap(initialSize, 0.75f, -1, -1); + this.indexMap = new Long2IntOpenHashMap(initialSize, 0.75f); + this.indexMap.defaultReturnValue(-1); } /** @@ -50,7 +52,8 @@ class IndexOfLongs extends IndexBase { */ IndexOfLongs(Iterable iterable) { super(iterable); - this.indexMap = new TLongIntHashMap(keyArray().length(), 0.75f, -1, -1); + this.indexMap = new Long2IntOpenHashMap(keyArray().length(), 0.75f); + this.indexMap.defaultReturnValue(-1); this.keyArray().sequential().forEachValue(v -> { final int index = v.index(); final long key = v.getLong(); @@ -68,7 +71,8 @@ class IndexOfLongs extends IndexBase { */ private IndexOfLongs(Iterable iterable, IndexOfLongs parent) { super(iterable, parent); - this.indexMap = new TLongIntHashMap(keyArray().length(), 0.75f, -1, -1); + this.indexMap = new Long2IntOpenHashMap(keyArray().length(), 0.75f); + this.indexMap.defaultReturnValue(-1); this.keyArray().sequential().forEachValue(v -> { final long key = v.getLong(); final int index = parent.indexMap.get(key); @@ -110,7 +114,7 @@ public final boolean add(Long key) { final int index = indexMap.size(); this.ensureCapacity(index + 1); this.keyArray().setValue(index, key); - this.indexMap.put(key, index); + this.indexMap.put((long) key, index); return true; } } @@ -143,7 +147,7 @@ public final int addAll(Iterable keys, boolean ignoreDuplicates) { public final Index copy() { try { final IndexOfLongs clone = (IndexOfLongs)super.copy(); - clone.indexMap = new TLongIntHashMap(indexMap); + clone.indexMap = new Long2IntOpenHashMap(indexMap); return clone; } catch (Exception ex) { throw new IndexException("Failed to clone index", ex); @@ -157,7 +161,7 @@ public int size() { @Override public int getIndexForKey(Long key) { - final int index = indexMap.get(key); + final int index = indexMap.get(key.longValue()); if (index < 0) { throw new IndexException("No match for key in index: " + key); } else { @@ -172,7 +176,7 @@ public boolean contains(Long key) { @Override public final int replace(Long existing, Long replacement) { - final int index = indexMap.remove(existing); + final int index = indexMap.remove(existing.longValue()); if (index == -1) { throw new IndexException("No match for key: " + existing); } else { @@ -180,7 +184,7 @@ public final int replace(Long existing, Long replacement) { throw new IndexException("The replacement key already exists: " + replacement); } else { final int ordinal = getOrdinalForIndex(index); - this.indexMap.put(replacement, index); + this.indexMap.put((long) replacement, index); this.keyArray().setValue(ordinal, replacement); return index; } @@ -192,7 +196,7 @@ public final void forEachEntry(IndexConsumer consumer) { final int size = size(); for (int i=0; i extends IndexBase { private static final long serialVersionUID = 1L; - private TObjectIntMap indexMap; + private Object2IntMap indexMap; /** * Constructor @@ -42,7 +42,8 @@ class IndexOfObjects extends IndexBase { */ IndexOfObjects(Class type, int initialSize) { super(Array.of(type, initialSize)); - this.indexMap = new TObjectIntHashMap<>(initialSize, 0.75f, -1); + this.indexMap = new Object2IntOpenHashMap<>(initialSize, 0.75f); + this.indexMap.defaultReturnValue(-1); } /** @@ -51,7 +52,8 @@ class IndexOfObjects extends IndexBase { */ IndexOfObjects(Iterable iterable) { super(iterable); - this.indexMap = new TObjectIntHashMap<>(keyArray().length(), 0.75f, -1); + this.indexMap = new Object2IntOpenHashMap<>(keyArray().length(), 0.75f); + this.indexMap.defaultReturnValue(-1); this.keyArray().sequential().forEachValue(v -> { final int index = v.index(); final K key = v.getValue(); @@ -69,10 +71,11 @@ class IndexOfObjects extends IndexBase { */ private IndexOfObjects(Iterable iterable, IndexOfObjects parent) { super(iterable, parent); - this.indexMap = new TObjectIntHashMap<>(keyArray().length(), 0.75f, -1); + this.indexMap = new Object2IntOpenHashMap<>(keyArray().length(), 0.75f); + this.indexMap.defaultReturnValue(-1); this.keyArray().sequential().forEachValue(v -> { final K key = v.getValue(); - final int index = parent.indexMap.get(key); + final int index = parent.indexMap.getInt(key); if (index < 0) throw new IndexException("No match for key: " + v.getValue()); final int existing = indexMap.put(key, index); if (existing >= 0) { @@ -145,7 +148,7 @@ public int addAll(Iterable keys, boolean ignoreDuplicates) { public final Index copy() { try { final IndexOfObjects clone = (IndexOfObjects)super.copy(); - clone.indexMap = new TObjectIntHashMap<>(indexMap); + clone.indexMap = new Object2IntOpenHashMap<>(indexMap); return clone; } catch (Exception ex) { throw new IndexException("Failed to clone index", ex); @@ -159,7 +162,7 @@ public final int size() { @Override public final int getIndexForKey(K key) { - final int index = indexMap.get(key); + final int index = indexMap.getInt(key); if (index < 0) { throw new IndexException("No match for key in index: " + key); } else { @@ -174,7 +177,7 @@ public final boolean contains(K key) { @Override public final int replace(K existing, K replacement) { - final int index = indexMap.remove(existing); + final int index = indexMap.removeInt(existing); if (index == -1) { throw new IndexException("No match key for " + existing); } else { @@ -194,7 +197,7 @@ public final void forEachEntry(IndexConsumer consumer) { final int size = size(); for (int i=0; i { private static final long serialVersionUID = 1L; - private TObjectIntMap indexMap; + private Object2IntMap indexMap; /** * Constructor @@ -41,7 +41,8 @@ class IndexOfStrings extends IndexBase { */ IndexOfStrings(int initialSize) { super(Array.of(String.class, initialSize)); - this.indexMap = new TObjectIntHashMap<>(initialSize, 0.75f, -1); + this.indexMap = new Object2IntOpenHashMap<>(initialSize, 0.75f); + this.indexMap.defaultReturnValue(-1); } /** @@ -50,7 +51,8 @@ class IndexOfStrings extends IndexBase { */ IndexOfStrings(Iterable iterable) { super(iterable); - this.indexMap = new TObjectIntHashMap<>(keyArray().length(), 0.75f, -1); + this.indexMap = new Object2IntOpenHashMap<>(keyArray().length(), 0.75f); + this.indexMap.defaultReturnValue(-1); this.keyArray().sequential().forEachValue(v -> { final int index = v.index(); final String key = v.getValue(); @@ -68,10 +70,11 @@ class IndexOfStrings extends IndexBase { */ private IndexOfStrings(Iterable iterable, IndexOfStrings parent) { super(iterable, parent); - this.indexMap = new TObjectIntHashMap<>(keyArray().length(), 0.75f, -1); + this.indexMap = new Object2IntOpenHashMap<>(keyArray().length(), 0.75f); + this.indexMap.defaultReturnValue(-1); this.keyArray().sequential().forEachValue(v -> { final String key = v.getValue(); - final int index = parent.indexMap.get(key); + final int index = parent.indexMap.getInt(key); if (index < 0) throw new IndexException("No match for key: " + v.getValue()); final int existing = indexMap.put(key, index); if (existing >= 0) { @@ -142,7 +145,7 @@ public final int addAll(Iterable keys, boolean ignoreDuplicates) { public final Index copy() { try { final IndexOfStrings clone = (IndexOfStrings)super.copy(); - clone.indexMap = new TObjectIntHashMap<>(indexMap); + clone.indexMap = new Object2IntOpenHashMap<>(indexMap); return clone; } catch (Exception ex) { throw new IndexException("Failed to clone index", ex); @@ -156,7 +159,7 @@ public final int size() { @Override public final int getIndexForKey(String key) { - final int index = indexMap.get(key); + final int index = indexMap.getInt(key); if (index < 0) { throw new IndexException("No match for key in index: " + key); } else { @@ -171,7 +174,7 @@ public final boolean contains(String key) { @Override public final int replace(String existing, String replacement) { - final int index = indexMap.remove(existing); + final int index = indexMap.removeInt(existing); if (index == -1) { throw new IndexException("No match key for " + existing); } else { @@ -191,7 +194,7 @@ public final void forEachEntry(IndexConsumer consumer) { final int size = size(); for (int i=0; i extends IndexBase implements WithIntCoding { private static final long serialVersionUID = 1L; - private TIntIntMap indexMap; + private Int2IntMap indexMap; private IntCoding coding; /** @@ -48,7 +48,8 @@ class IndexWithIntCoding extends IndexBase implements WithIntCoding { IndexWithIntCoding(Class type, IntCoding coding, int capacity) { super(Array.of(type, capacity)); this.coding = coding; - this.indexMap = new TIntIntHashMap(capacity, 0.75f, -1, -1); + this.indexMap = new Int2IntOpenHashMap(capacity, 0.75f); + this.indexMap.defaultReturnValue(-1); } /** @@ -59,7 +60,8 @@ class IndexWithIntCoding extends IndexBase implements WithIntCoding { IndexWithIntCoding(Iterable iterable, IntCoding coding) { super(iterable); this.coding = coding; - this.indexMap = new TIntIntHashMap(keyArray().length(), 0.75f, -1, -1); + this.indexMap = new Int2IntOpenHashMap(keyArray().length(), 0.75f); + this.indexMap.defaultReturnValue(-1); this.keyArray().sequential().forEachValue(v -> { final int index = v.index(); final int code = v.getInt(); @@ -79,7 +81,8 @@ class IndexWithIntCoding extends IndexBase implements WithIntCoding { private IndexWithIntCoding(Iterable iterable, IntCoding coding, IndexWithIntCoding parent) { super(iterable, parent); this.coding = coding; - this.indexMap = new TIntIntHashMap(keyArray().length(), 0.75f, -1, -1); + this.indexMap = new Int2IntOpenHashMap(keyArray().length(), 0.75f); + this.indexMap.defaultReturnValue(-1); this.keyArray().sequential().forEachValue(v -> { final int code = v.getInt(); final int index = parent.indexMap.get(code); @@ -164,7 +167,7 @@ public final int addAll(Iterable keys, boolean ignoreDuplicates) { public final Index copy() { try { final IndexWithIntCoding clone = (IndexWithIntCoding)super.copy(); - clone.indexMap = new TIntIntHashMap(indexMap); + clone.indexMap = new Int2IntOpenHashMap(indexMap); clone.coding = coding; return clone; } catch (Exception ex) { diff --git a/src/main/java/com/zavtech/morpheus/index/IndexWithLongCoding.java b/src/main/java/com/zavtech/morpheus/index/IndexWithLongCoding.java index 2ff9ef5..d3c4e1e 100644 --- a/src/main/java/com/zavtech/morpheus/index/IndexWithLongCoding.java +++ b/src/main/java/com/zavtech/morpheus/index/IndexWithLongCoding.java @@ -22,8 +22,8 @@ import com.zavtech.morpheus.array.coding.LongCoding; import com.zavtech.morpheus.array.coding.WithLongCoding; -import gnu.trove.map.TLongIntMap; -import gnu.trove.map.hash.TLongIntHashMap; +import it.unimi.dsi.fastutil.longs.Long2IntMap; +import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap; /** * An Index implementation designed to efficiently store Object values that can be coded as a long value @@ -36,7 +36,7 @@ class IndexWithLongCoding extends IndexBase implements WithLongCoding { private static final long serialVersionUID = 1L; - private TLongIntMap indexMap; + private Long2IntMap indexMap; private LongCoding coding; /** @@ -48,7 +48,8 @@ class IndexWithLongCoding extends IndexBase implements WithLongCoding { IndexWithLongCoding(Class type, LongCoding coding, int capacity) { super(Array.of(type, capacity)); this.coding = coding; - this.indexMap = new TLongIntHashMap(capacity, 0.75f, -1L, -1); + this.indexMap = new Long2IntOpenHashMap(capacity, 0.75f); + this.indexMap.defaultReturnValue(-1); } /** @@ -59,7 +60,8 @@ class IndexWithLongCoding extends IndexBase implements WithLongCoding { IndexWithLongCoding(Iterable iterable, LongCoding coding) { super(iterable); this.coding = coding; - this.indexMap = new TLongIntHashMap(keyArray().length(), 0.75f, -1L, -1); + this.indexMap = new Long2IntOpenHashMap(keyArray().length(), 0.75f); + this.indexMap.defaultReturnValue(-1); this.keyArray().sequential().forEachValue(v -> { final int index = v.index(); final long code = v.getLong(); @@ -79,7 +81,8 @@ class IndexWithLongCoding extends IndexBase implements WithLongCoding { private IndexWithLongCoding(Iterable iterable, LongCoding coding, IndexWithLongCoding parent) { super(iterable, parent); this.coding = coding; - this.indexMap = new TLongIntHashMap(keyArray().length(), 0.75f, -1L, -1); + this.indexMap = new Long2IntOpenHashMap(keyArray().length(), 0.75f); + this.indexMap.defaultReturnValue(-1); this.keyArray().sequential().forEachValue(v -> { final long code = v.getLong(); final int index = parent.indexMap.get(code); @@ -164,7 +167,7 @@ public final int addAll(Iterable keys, boolean ignoreDuplicates) { public final Index copy() { try { final IndexWithLongCoding clone = (IndexWithLongCoding)super.copy(); - clone.indexMap = new TLongIntHashMap(indexMap); + clone.indexMap = new Long2IntOpenHashMap(indexMap); clone.coding = coding; return clone; } catch (Exception ex) { diff --git a/src/test/java/com/zavtech/morpheus/reference/CreateTests.java b/src/test/java/com/zavtech/morpheus/reference/CreateTests.java index 770b6f3..1ca4bcd 100644 --- a/src/test/java/com/zavtech/morpheus/reference/CreateTests.java +++ b/src/test/java/com/zavtech/morpheus/reference/CreateTests.java @@ -17,15 +17,17 @@ import java.time.LocalDate; +import org.testng.annotations.Test; + import com.zavtech.morpheus.frame.DataFrame; import com.zavtech.morpheus.frame.DataFrameAsserts; import com.zavtech.morpheus.index.Index; import com.zavtech.morpheus.range.Range; -import gnu.trove.map.TLongIntMap; -import gnu.trove.map.TObjectIntMap; -import gnu.trove.map.hash.TLongIntHashMap; -import gnu.trove.map.hash.TObjectIntHashMap; -import org.testng.annotations.Test; + +import it.unimi.dsi.fastutil.longs.Long2IntMap; +import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap; +import it.unimi.dsi.fastutil.objects.Object2IntMap; +import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; /** * A unit test to exercise the various mechanisms for constructing DataFrames. @@ -84,9 +86,9 @@ public void testConstruction1() { @Test() public void testMapCreateTest() { final long t1 = System.nanoTime(); - final TObjectIntMap map1 = new TObjectIntHashMap<>(5000000, 0.8f, -1); + final Object2IntMap map1 = new Object2IntOpenHashMap<>(5000000, 0.8f); final long t2 = System.nanoTime(); - final TLongIntMap map2 = new TLongIntHashMap(); + final Long2IntMap map2 = new Long2IntOpenHashMap(); final long t3 = System.nanoTime(); System.out.println("Map1:" + ((t2-t1)/1000000d) + " Map2:" + ((t3-t2)/100000d)); }