From 651239fca4446b73882c9c1c5cb7e43cd52e2b43 Mon Sep 17 00:00:00 2001 From: Ben McCann Date: Thu, 17 Aug 2017 14:07:16 -0700 Subject: [PATCH 1/2] Switch from trove to fastutil --- .gitignore | 6 +++++ pom.xml | 6 ++--- .../com/zavtech/morpheus/array/ArrayBase.java | 4 ++- .../zavtech/morpheus/array/ArrayUtils.java | 26 +++++++++--------- .../morpheus/array/coding/IntCoding.java | 21 ++++++++------- .../array/dense/DenseArrayOfBooleans.java | 12 ++++----- .../array/dense/DenseArrayOfDoubles.java | 12 ++++----- .../array/dense/DenseArrayOfInts.java | 8 +++--- .../array/dense/DenseArrayOfLongs.java | 8 +++--- .../array/dense/DenseArrayWithIntCoding.java | 8 +++--- .../array/dense/DenseArrayWithLongCoding.java | 8 +++--- .../array/mapped/MappedArrayOfBooleans.java | 12 ++++----- .../array/mapped/MappedArrayOfDoubles.java | 8 +++--- .../array/mapped/MappedArrayOfInts.java | 8 +++--- .../array/mapped/MappedArrayOfLongs.java | 8 +++--- .../mapped/MappedArrayWithIntCoding.java | 8 +++--- .../mapped/MappedArrayWithLongCoding.java | 8 +++--- .../array/sparse/SparseArrayOfDoubles.java | 21 ++++++++------- .../array/sparse/SparseArrayOfInts.java | 23 ++++++++-------- .../array/sparse/SparseArrayOfLongs.java | 23 ++++++++-------- .../array/sparse/SparseArrayOfObjects.java | 13 ++++----- .../sparse/SparseArrayOfZonedDateTimes.java | 24 +++++++++-------- .../sparse/SparseArrayWithIntCoding.java | 19 ++++++------- .../sparse/SparseArrayWithLongCoding.java | 19 ++++++------- .../morpheus/index/IndexOfDoubles.java | 22 ++++++++------- .../zavtech/morpheus/index/IndexOfInts.java | 27 ++++++++++--------- .../zavtech/morpheus/index/IndexOfLongs.java | 22 ++++++++------- .../morpheus/index/IndexOfObjects.java | 17 +++++++----- .../morpheus/index/IndexOfStrings.java | 17 +++++++----- .../morpheus/index/IndexWithIntCoding.java | 17 +++++++----- .../morpheus/index/IndexWithLongCoding.java | 17 +++++++----- .../morpheus/reference/CreateTests.java | 16 ++++++----- 32 files changed, 255 insertions(+), 213 deletions(-) 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..422ca8b 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); } diff --git a/src/main/java/com/zavtech/morpheus/array/ArrayUtils.java b/src/main/java/com/zavtech/morpheus/array/ArrayUtils.java index 47d7606..041fc29 100644 --- a/src/main/java/com/zavtech/morpheus/array/ArrayUtils.java +++ b/src/main/java/com/zavtech/morpheus/array/ArrayUtils.java @@ -30,16 +30,16 @@ import java.util.stream.LongStream; import java.util.stream.Stream; -import gnu.trove.set.TDoubleSet; -import gnu.trove.set.TIntSet; -import gnu.trove.set.TLongSet; -import gnu.trove.set.hash.TDoubleHashSet; -import gnu.trove.set.hash.TIntHashSet; -import gnu.trove.set.hash.TLongHashSet; - import com.zavtech.morpheus.index.Index; import com.zavtech.morpheus.range.Range; +import it.unimi.dsi.fastutil.doubles.DoubleOpenHashSet; +import it.unimi.dsi.fastutil.doubles.DoubleSet; +import it.unimi.dsi.fastutil.ints.IntOpenHashSet; +import it.unimi.dsi.fastutil.ints.IntSet; +import it.unimi.dsi.fastutil.longs.LongOpenHashSet; +import it.unimi.dsi.fastutil.longs.LongSet; + /** * A utility class that provides various useful functions to operate on Morpheus arrays * @@ -219,7 +219,7 @@ public final Array toArray() { private static class DistinctInts extends DistinctCalculator { private int limit; - private TIntSet distinctSet; + private IntSet distinctSet; /** * Constructor @@ -228,7 +228,7 @@ private static class DistinctInts extends DistinctCalculator { DistinctInts(int limit) { super(Integer.class, limit); this.limit = limit; - this.distinctSet = new TIntHashSet(limit < Integer.MAX_VALUE ? limit : 1000); + this.distinctSet = new IntOpenHashSet(limit < Integer.MAX_VALUE ? limit : 1000); } /** @@ -250,7 +250,7 @@ public final boolean add(int value) { private static class DistinctLongs extends DistinctCalculator { private int limit; - private TLongSet distinctSet; + private LongSet distinctSet; /** * Constructor @@ -259,7 +259,7 @@ private static class DistinctLongs extends DistinctCalculator { DistinctLongs(int limit) { super(Long.class, limit); this.limit = limit; - this.distinctSet = new TLongHashSet(limit < Integer.MAX_VALUE ? limit : 1000); + this.distinctSet = new LongOpenHashSet(limit < Integer.MAX_VALUE ? limit : 1000); } /** @@ -280,7 +280,7 @@ public final boolean add(long value) { private static class DistinctDoubles extends DistinctCalculator { private int limit; - private TDoubleSet distinctSet; + private DoubleSet distinctSet; /** * Constructor @@ -289,7 +289,7 @@ private static class DistinctDoubles extends DistinctCalculator { DistinctDoubles(int limit) { super(Double.class, limit); this.limit = limit; - this.distinctSet = new TDoubleHashSet(limit < Integer.MAX_VALUE ? limit : 1000); + this.distinctSet = new DoubleOpenHashSet(limit < Integer.MAX_VALUE ? limit : 1000); } /** 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..f5d6f68 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); @@ -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 { 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); 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..985eac8 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,7 @@ public int binarySearch(int start, int end, Boolean value) { @Override public Array distinct(int limit) { - final TShortSet set = new TShortHashSet(limit); + final ShortSet set = new ShortOpenHashSet(limit); 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 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 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 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 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 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 ShortSet set = new ShortOpenHashSet(limit); 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 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 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 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 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 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; } } @@ -306,7 +307,7 @@ 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 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; } } @@ -317,7 +318,7 @@ 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 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; } } @@ -313,7 +314,7 @@ 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 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..770f228 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; @@ -287,7 +288,7 @@ 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 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; @@ -298,7 +299,7 @@ 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 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); @@ -180,7 +184,7 @@ public final int replace(Double existing, Double replacement) { 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; } diff --git a/src/main/java/com/zavtech/morpheus/index/IndexOfInts.java b/src/main/java/com/zavtech/morpheus/index/IndexOfInts.java index 1ae3ab4..3869362 100644 --- a/src/main/java/com/zavtech/morpheus/index/IndexOfInts.java +++ b/src/main/java/com/zavtech/morpheus/index/IndexOfInts.java @@ -21,8 +21,8 @@ import com.zavtech.morpheus.array.ArrayBuilder; import com.zavtech.morpheus.util.IntComparator; -import gnu.trove.map.TIntIntMap; -import gnu.trove.map.hash.TIntIntHashMap; +import it.unimi.dsi.fastutil.ints.Int2IntMap; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; /** * An Index implementation designed to efficiently store integer values @@ -35,7 +35,7 @@ class IndexOfInts extends IndexBase { 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); @@ -115,7 +118,7 @@ public final boolean add(Integer key) { 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); @@ -185,7 +188,7 @@ public final int replace(Integer existing, Integer replacement) { 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; } @@ -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..a3e801a 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); @@ -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; } diff --git a/src/main/java/com/zavtech/morpheus/index/IndexOfObjects.java b/src/main/java/com/zavtech/morpheus/index/IndexOfObjects.java index 2d4cd54..2f4afe5 100644 --- a/src/main/java/com/zavtech/morpheus/index/IndexOfObjects.java +++ b/src/main/java/com/zavtech/morpheus/index/IndexOfObjects.java @@ -19,8 +19,8 @@ import com.zavtech.morpheus.array.Array; import com.zavtech.morpheus.array.ArrayBuilder; -import gnu.trove.map.TObjectIntMap; -import gnu.trove.map.hash.TObjectIntHashMap; +import it.unimi.dsi.fastutil.objects.Object2IntMap; +import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; /** * An Index implementation designed to store any object type. @@ -33,7 +33,7 @@ class IndexOfObjects 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,7 +71,8 @@ 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); @@ -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); diff --git a/src/main/java/com/zavtech/morpheus/index/IndexOfStrings.java b/src/main/java/com/zavtech/morpheus/index/IndexOfStrings.java index e551b16..9d20ffe 100644 --- a/src/main/java/com/zavtech/morpheus/index/IndexOfStrings.java +++ b/src/main/java/com/zavtech/morpheus/index/IndexOfStrings.java @@ -19,8 +19,8 @@ import com.zavtech.morpheus.array.Array; import com.zavtech.morpheus.array.ArrayBuilder; -import gnu.trove.map.TObjectIntMap; -import gnu.trove.map.hash.TObjectIntHashMap; +import it.unimi.dsi.fastutil.objects.Object2IntMap; +import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; /** * An Index implementation designed to efficiently store String values @@ -33,7 +33,7 @@ class IndexOfStrings extends IndexBase { 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,7 +70,8 @@ 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); @@ -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); diff --git a/src/main/java/com/zavtech/morpheus/index/IndexWithIntCoding.java b/src/main/java/com/zavtech/morpheus/index/IndexWithIntCoding.java index 0188a91..8ce4942 100644 --- a/src/main/java/com/zavtech/morpheus/index/IndexWithIntCoding.java +++ b/src/main/java/com/zavtech/morpheus/index/IndexWithIntCoding.java @@ -22,8 +22,8 @@ import com.zavtech.morpheus.array.coding.IntCoding; import com.zavtech.morpheus.array.coding.WithIntCoding; -import gnu.trove.map.TIntIntMap; -import gnu.trove.map.hash.TIntIntHashMap; +import it.unimi.dsi.fastutil.ints.Int2IntMap; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; /** * An Index implementation designed to efficiently store Object values that can be coded as a long value @@ -36,7 +36,7 @@ class IndexWithIntCoding 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)); } From ab35ff4109631cb6ba7ee30e9f5a86caf021e530 Mon Sep 17 00:00:00 2001 From: zavster Date: Mon, 21 Aug 2017 21:33:24 -0400 Subject: [PATCH 2/2] Use non-deprecated methods in Fasutil and fix test errors --- .../com/zavtech/morpheus/array/ArrayBase.java | 2 +- .../zavtech/morpheus/array/ArrayUtils.java | 43 +++++++++++-------- .../morpheus/array/coding/IntCoding.java | 6 +-- .../array/dense/DenseArrayOfBooleans.java | 3 +- .../array/dense/DenseArrayOfDoubles.java | 2 +- .../array/dense/DenseArrayOfInts.java | 2 +- .../array/dense/DenseArrayOfLongs.java | 2 +- .../array/dense/DenseArrayWithIntCoding.java | 2 +- .../array/dense/DenseArrayWithLongCoding.java | 2 +- .../array/mapped/MappedArrayOfBooleans.java | 3 +- .../array/mapped/MappedArrayOfDoubles.java | 2 +- .../array/mapped/MappedArrayOfInts.java | 2 +- .../array/mapped/MappedArrayOfLongs.java | 2 +- .../mapped/MappedArrayWithIntCoding.java | 2 +- .../mapped/MappedArrayWithLongCoding.java | 2 +- .../array/sparse/SparseArrayOfDoubles.java | 2 +- .../array/sparse/SparseArrayOfInts.java | 2 +- .../array/sparse/SparseArrayOfLongs.java | 2 +- .../sparse/SparseArrayWithIntCoding.java | 2 +- .../sparse/SparseArrayWithLongCoding.java | 2 +- .../morpheus/index/IndexOfDoubles.java | 8 ++-- .../zavtech/morpheus/index/IndexOfInts.java | 12 +++--- .../zavtech/morpheus/index/IndexOfLongs.java | 6 +-- .../morpheus/index/IndexOfObjects.java | 8 ++-- .../morpheus/index/IndexOfStrings.java | 8 ++-- 25 files changed, 68 insertions(+), 61 deletions(-) diff --git a/src/main/java/com/zavtech/morpheus/array/ArrayBase.java b/src/main/java/com/zavtech/morpheus/array/ArrayBase.java index 422ca8b..cfddae3 100644 --- a/src/main/java/com/zavtech/morpheus/array/ArrayBase.java +++ b/src/main/java/com/zavtech/morpheus/array/ArrayBase.java @@ -198,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); } /** @@ -224,11 +228,12 @@ private static class DistinctInts extends DistinctCalculator { /** * 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 IntOpenHashSet(limit < Integer.MAX_VALUE ? limit : 1000); + this.distinctSet = new IntOpenHashSet(capacity); } /** @@ -256,10 +261,10 @@ private static class DistinctLongs extends DistinctCalculator { * 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 LongOpenHashSet(limit < Integer.MAX_VALUE ? limit : 1000); + this.distinctSet = new LongOpenHashSet(capacity); } /** @@ -286,10 +291,10 @@ private static class DistinctDoubles extends DistinctCalculator { * 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 DoubleOpenHashSet(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 f5d6f68..4d7368f 100644 --- a/src/main/java/com/zavtech/morpheus/array/coding/IntCoding.java +++ b/src/main/java/com/zavtech/morpheus/array/coding/IntCoding.java @@ -187,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 @@ -223,7 +223,7 @@ class OfZoneId extends BaseCoding implements IntCoding { @Override public final int getCode(ZoneId value) { - return value == null ? -1 : codeMap.get(value); + return value == null ? -1 : codeMap.getInt(value); } @Override @@ -259,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 985eac8..848f121 100644 --- a/src/main/java/com/zavtech/morpheus/array/dense/DenseArrayOfBooleans.java +++ b/src/main/java/com/zavtech/morpheus/array/dense/DenseArrayOfBooleans.java @@ -281,7 +281,8 @@ public int binarySearch(int start, int end, Boolean value) { @Override public Array distinct(int limit) { - final ShortSet set = new ShortOpenHashSet(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 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 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 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 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 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 ShortSet set = new ShortOpenHashSet(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 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 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 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 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 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 int capacity = limit < Integer.MAX_VALUE ? limit : 100; + 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 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 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 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 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 consumer) { final int size = size(); for (int i=0; i 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); } } diff --git a/src/main/java/com/zavtech/morpheus/index/IndexOfLongs.java b/src/main/java/com/zavtech/morpheus/index/IndexOfLongs.java index a3e801a..6b27875 100644 --- a/src/main/java/com/zavtech/morpheus/index/IndexOfLongs.java +++ b/src/main/java/com/zavtech/morpheus/index/IndexOfLongs.java @@ -161,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 { @@ -176,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 { @@ -196,7 +196,7 @@ public final void forEachEntry(IndexConsumer consumer) { final int size = size(); for (int i=0; i iterable, IndexOfObjects parent) { 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) { @@ -162,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 { @@ -177,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 { @@ -197,7 +197,7 @@ public final void forEachEntry(IndexConsumer consumer) { final int size = size(); for (int i=0; i iterable, IndexOfStrings parent) { 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) { @@ -159,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 { @@ -174,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 { @@ -194,7 +194,7 @@ public final void forEachEntry(IndexConsumer consumer) { final int size = size(); for (int i=0; i