* BAEL-4154 IOException Too many open files

* Add comment to explain GC dependency

* Add HPPC, remove Colt & Trove

* Add inplace iterators for fastutil and extra maps for HPPC

Co-authored-by: Carlos Grappa <carlos.grappa@mercadolibre.com>
This commit is contained in:
Carlos Grappa 2020-08-15 17:59:34 -03:00 committed by GitHub
parent 2ac7e8af89
commit bb34174aeb
2 changed files with 61 additions and 34 deletions

View File

@ -21,20 +21,15 @@
<version>${eclipse-collections.version}</version>
</dependency>
<dependency>
<groupId>net.sf.trove4j</groupId>
<artifactId>trove4j</artifactId>
<version>${trove4j.version}</version>
<groupId>com.carrotsearch</groupId>
<artifactId>hppc</artifactId>
<version>${hppc.version}</version>
</dependency>
<dependency>
<groupId>it.unimi.dsi</groupId>
<artifactId>fastutil</artifactId>
<version>${fastutil.version}</version>
</dependency>
<dependency>
<groupId>colt</groupId>
<artifactId>colt</artifactId>
<version>${colt.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
@ -69,9 +64,8 @@
<commons-collections4.version>4.1</commons-collections4.version>
<avaitility.version>1.7.0</avaitility.version>
<eclipse-collections.version>8.2.0</eclipse-collections.version>
<trove4j.version>3.0.2</trove4j.version>
<hppc.version>0.7.2</hppc.version>
<fastutil.version>8.1.0</fastutil.version>
<colt.version>1.2.0</colt.version>
<assertj.version>3.11.1</assertj.version>
</properties>

View File

@ -1,29 +1,68 @@
package com.baeldung.map.primitives;
import cern.colt.map.AbstractIntDoubleMap;
import cern.colt.map.OpenIntDoubleHashMap;
import gnu.trove.map.TDoubleIntMap;
import gnu.trove.map.hash.TDoubleIntHashMap;
import com.carrotsearch.hppc.IntLongHashMap;
import com.carrotsearch.hppc.IntLongScatterMap;
import com.carrotsearch.hppc.IntObjectHashMap;
import com.carrotsearch.hppc.IntObjectMap;
import com.carrotsearch.hppc.IntObjectScatterMap;
import it.unimi.dsi.fastutil.ints.Int2BooleanMap;
import it.unimi.dsi.fastutil.ints.Int2BooleanMaps;
import it.unimi.dsi.fastutil.ints.Int2BooleanOpenHashMap;
import it.unimi.dsi.fastutil.ints.Int2BooleanSortedMap;
import it.unimi.dsi.fastutil.ints.Int2BooleanSortedMaps;
import it.unimi.dsi.fastutil.objects.ObjectIterator;
import org.eclipse.collections.api.map.primitive.ImmutableIntIntMap;
import org.eclipse.collections.api.map.primitive.MutableIntIntMap;
import org.eclipse.collections.api.map.primitive.MutableObjectDoubleMap;
import org.eclipse.collections.impl.factory.primitive.IntIntMaps;
import org.eclipse.collections.impl.factory.primitive.ObjectDoubleMaps;
import static java.lang.String.format;
import java.math.BigDecimal;
public class PrimitiveMaps {
public static void main(String[] args) {
hppcMap();
eclipseCollectionsMap();
troveMap();
coltMap();
fastutilMap();
}
private static void hppcMap() {
//Regular maps
IntLongHashMap intLongHashMap = new IntLongHashMap();
intLongHashMap.put(25,1L);
intLongHashMap.put(150,Long.MAX_VALUE);
intLongHashMap.put(1,0L);
intLongHashMap.get(150);
IntObjectMap<BigDecimal> intObjectMap = new IntObjectHashMap<BigDecimal>();
intObjectMap.put(1, BigDecimal.valueOf(1));
intObjectMap.put(2, BigDecimal.valueOf(2500));
BigDecimal value = intObjectMap.get(2);
//Scatter maps
IntLongScatterMap intLongScatterMap = new IntLongScatterMap();
intLongScatterMap.put(1, 1L);
intLongScatterMap.put(2, -2L);
intLongScatterMap.put(1000,0L);
intLongScatterMap.get(1000);
IntObjectScatterMap<BigDecimal> intObjectScatterMap = new IntObjectScatterMap<BigDecimal>();
intObjectScatterMap.put(1, BigDecimal.valueOf(1));
intObjectScatterMap.put(2, BigDecimal.valueOf(2500));
value = intObjectScatterMap.get(2);
}
private static void fastutilMap() {
Int2BooleanMap int2BooleanMap = new Int2BooleanOpenHashMap();
int2BooleanMap.put(1, true);
@ -32,13 +71,19 @@ public class PrimitiveMaps {
boolean value = int2BooleanMap.get(1);
Int2BooleanSortedMap int2BooleanSorted = Int2BooleanSortedMaps.EMPTY_MAP;
}
//Lambda style iteration
Int2BooleanMaps.fastForEach(int2BooleanMap, entry -> {
System.out.println(String.format("Key: %d, Value: %b",entry.getIntKey(),entry.getBooleanValue()));
});
//Iterator based loop
ObjectIterator<Int2BooleanMap.Entry> iterator = Int2BooleanMaps.fastIterator(int2BooleanMap);
while(iterator.hasNext()) {
Int2BooleanMap.Entry entry = iterator.next();
System.out.println(String.format("Key: %d, Value: %b",entry.getIntKey(),entry.getBooleanValue()));
}
private static void coltMap() {
AbstractIntDoubleMap map = new OpenIntDoubleHashMap();
map.put(1, 4.5);
double value = map.get(1);
}
private static void eclipseCollectionsMap() {
@ -53,17 +98,5 @@ public class PrimitiveMaps {
dObject.addToValue("stability", 0.8);
}
private static void troveMap() {
double[] doubles = new double[] {1.2, 4.5, 0.3};
int[] ints = new int[] {1, 4, 0};
TDoubleIntMap doubleIntMap = new TDoubleIntHashMap(doubles, ints);
doubleIntMap.put(1.2, 22);
doubleIntMap.put(4.5, 16);
doubleIntMap.adjustValue(1.2, 1);
doubleIntMap.adjustValue(4.5, 4);
doubleIntMap.adjustValue(0.3, 7);
}
}