diff --git a/jgalgo-core/pom.xml b/jgalgo-core/pom.xml index c359830820..a5a4263325 100644 --- a/jgalgo-core/pom.xml +++ b/jgalgo-core/pom.xml @@ -15,7 +15,7 @@ it.unimi.dsi - fastutil + fastutil-core ${fastutil.version} diff --git a/jgalgo-core/src/main/java/com/jgalgo/alg/EulerianTourAlgo.java b/jgalgo-core/src/main/java/com/jgalgo/alg/EulerianTourAlgo.java index bc1548fe37..8a993da5c3 100644 --- a/jgalgo-core/src/main/java/com/jgalgo/alg/EulerianTourAlgo.java +++ b/jgalgo-core/src/main/java/com/jgalgo/alg/EulerianTourAlgo.java @@ -24,7 +24,6 @@ import com.jgalgo.graph.IntGraph; import com.jgalgo.internal.util.Bitmap; import com.jgalgo.internal.util.IntAdapters; -import it.unimi.dsi.fastutil.booleans.BooleanList; import it.unimi.dsi.fastutil.ints.IntIterator; import it.unimi.dsi.fastutil.ints.IntList; @@ -148,7 +147,7 @@ static boolean isEulerianTour(Graph g, List tour) { } else { int firstEdge = tour0.getInt(0); boolean foundValidStartingEndpoint = false; - startingEndpointLoop: for (boolean startingEndpoint : BooleanList.of(true, false)) { + startingEndpointLoop: for (boolean startingEndpoint : new boolean[] { true, false }) { visited.clear(); int u = startingEndpoint ? ig.edgeSource(firstEdge) : ig.edgeTarget(firstEdge); IntIterator it = tour0.iterator(); diff --git a/jgalgo-core/src/main/java/com/jgalgo/alg/IVertexBiPartition.java b/jgalgo-core/src/main/java/com/jgalgo/alg/IVertexBiPartition.java index 0fbc884e77..c80ae26a31 100644 --- a/jgalgo-core/src/main/java/com/jgalgo/alg/IVertexBiPartition.java +++ b/jgalgo-core/src/main/java/com/jgalgo/alg/IVertexBiPartition.java @@ -15,12 +15,12 @@ */ package com.jgalgo.alg; +import java.util.Map; import java.util.function.IntPredicate; import com.jgalgo.graph.IndexGraph; import com.jgalgo.graph.IndexIntIdMap; import com.jgalgo.graph.IntGraph; import com.jgalgo.internal.util.Bitmap; -import it.unimi.dsi.fastutil.ints.Int2BooleanMap; import it.unimi.dsi.fastutil.ints.IntSet; /** @@ -125,7 +125,7 @@ default IntSet crossEdges() { * @param map a map from vertex to either {@code true} or {@code false} * @return a new vertex bi-partition */ - static IVertexBiPartition fromMap(IntGraph g, Int2BooleanMap map) { + static IVertexBiPartition fromMap(IntGraph g, Map map) { return fromMapping(g, map::get); } diff --git a/jgalgo-core/src/main/java/com/jgalgo/alg/MatchingWeightedBlossomV.java b/jgalgo-core/src/main/java/com/jgalgo/alg/MatchingWeightedBlossomV.java index f475a626c1..247bf480e7 100644 --- a/jgalgo-core/src/main/java/com/jgalgo/alg/MatchingWeightedBlossomV.java +++ b/jgalgo-core/src/main/java/com/jgalgo/alg/MatchingWeightedBlossomV.java @@ -31,8 +31,8 @@ import com.jgalgo.internal.ds.ReferenceableHeap; import com.jgalgo.internal.util.Assertions; import com.jgalgo.internal.util.DebugPrinter; -import it.unimi.dsi.fastutil.objects.Reference2IntMap; -import it.unimi.dsi.fastutil.objects.Reference2IntOpenHashMap; +import it.unimi.dsi.fastutil.objects.Object2IntMap; +import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; /** * Blossom V implementation for maximum weighted matching. @@ -2783,7 +2783,7 @@ private static class Debug { private static class Impl { private int nextBlossomId; - private final Reference2IntMap blossomIds = new Reference2IntOpenHashMap<>(); + private final Object2IntMap blossomIds = new Object2IntOpenHashMap<>(); } static String blossomId(Blossom b) { diff --git a/jgalgo-core/src/main/java/com/jgalgo/alg/VertexBiPartition.java b/jgalgo-core/src/main/java/com/jgalgo/alg/VertexBiPartition.java index 09ea3120b2..db2f9c72db 100644 --- a/jgalgo-core/src/main/java/com/jgalgo/alg/VertexBiPartition.java +++ b/jgalgo-core/src/main/java/com/jgalgo/alg/VertexBiPartition.java @@ -15,6 +15,7 @@ */ package com.jgalgo.alg; +import java.util.Map; import java.util.Set; import java.util.function.IntPredicate; import java.util.function.Predicate; @@ -23,7 +24,6 @@ import com.jgalgo.graph.IntGraph; import com.jgalgo.internal.util.Bitmap; import com.jgalgo.internal.util.IntAdapters; -import it.unimi.dsi.fastutil.objects.Object2BooleanMap; /** * A partition of the vertices of a graph into two blocks. @@ -149,8 +149,8 @@ default Set crossEdges() { * @param map a map from vertex to either {@code true} or {@code false} * @return a new vertex bi-partition */ - static VertexBiPartition fromMap(Graph g, Object2BooleanMap map) { - return fromMapping(g, map::getBoolean); + static VertexBiPartition fromMap(Graph g, Map map) { + return fromMapping(g, map::get); } /** diff --git a/jgalgo-core/src/main/java/com/jgalgo/graph/IndexGraphFactoryImpl.java b/jgalgo-core/src/main/java/com/jgalgo/graph/IndexGraphFactoryImpl.java index 7212688136..e9dcce59f2 100644 --- a/jgalgo-core/src/main/java/com/jgalgo/graph/IndexGraphFactoryImpl.java +++ b/jgalgo-core/src/main/java/com/jgalgo/graph/IndexGraphFactoryImpl.java @@ -17,9 +17,9 @@ import java.util.EnumSet; import java.util.Optional; +import java.util.function.Function; import com.jgalgo.graph.IndexGraphBuilder.ReIndexedGraph; import com.jgalgo.graph.IndexGraphBuilderImpl.ReIndexedGraphImpl; -import it.unimi.dsi.fastutil.booleans.Boolean2ObjectFunction; class IndexGraphFactoryImpl implements IndexGraphFactory { @@ -89,8 +89,9 @@ default IndexGraphBuilder.ReIndexedGraph newFromBuilderWithReIndex(IndexGraphBui } + @SuppressWarnings("boxing") MutableImpl mutableImpl() { - Boolean2ObjectFunction arrayImplFactory = selfEdges -> { + Function arrayImplFactory = selfEdges -> { return directed ? new MutableImpl() { @Override @@ -125,10 +126,10 @@ public IndexGraph newFromBuilder(IndexGraphBuilderImpl builder) { } }; }; - MutableImpl arrayImpl = arrayImplFactory.get(false); - MutableImpl arrayImplWithSelfEdges = arrayImplFactory.get(true); + MutableImpl arrayImpl = arrayImplFactory.apply(false); + MutableImpl arrayImplWithSelfEdges = arrayImplFactory.apply(true); - Boolean2ObjectFunction linkedImplFactory = selfEdges -> { + Function linkedImplFactory = selfEdges -> { return directed ? new MutableImpl() { @Override @@ -163,9 +164,9 @@ public IndexGraph newFromBuilder(IndexGraphBuilderImpl builder) { } }; }; - MutableImpl linkedImpl = linkedImplFactory.get(false); - MutableImpl linkedImplWithSelfEdges = linkedImplFactory.get(true); - Boolean2ObjectFunction linkedPtrImplFactory = selfEdges -> { + MutableImpl linkedImpl = linkedImplFactory.apply(false); + MutableImpl linkedImplWithSelfEdges = linkedImplFactory.apply(true); + Function linkedPtrImplFactory = selfEdges -> { return directed ? new MutableImpl() { @Override @@ -200,9 +201,9 @@ public IndexGraph newFromBuilder(IndexGraphBuilderImpl builder) { } }; }; - MutableImpl linkedPtrImpl = linkedPtrImplFactory.get(false); - MutableImpl linkedPtrImplWithSelfEdges = linkedPtrImplFactory.get(true); - Boolean2ObjectFunction hashtableImplFactory = selfEdges -> { + MutableImpl linkedPtrImpl = linkedPtrImplFactory.apply(false); + MutableImpl linkedPtrImplWithSelfEdges = linkedPtrImplFactory.apply(true); + Function hashtableImplFactory = selfEdges -> { return directed ? new MutableImpl() { @Override @@ -237,9 +238,9 @@ public IndexGraph newFromBuilder(IndexGraphBuilderImpl builder) { } }; }; - MutableImpl hashtableImpl = hashtableImplFactory.get(false); - MutableImpl hashtableImplWithSelfEdges = hashtableImplFactory.get(true); - Boolean2ObjectFunction hashtableMultiImplFactory = selfEdges -> { + MutableImpl hashtableImpl = hashtableImplFactory.apply(false); + MutableImpl hashtableImplWithSelfEdges = hashtableImplFactory.apply(true); + Function hashtableMultiImplFactory = selfEdges -> { return directed ? new MutableImpl() { @Override @@ -274,9 +275,9 @@ public IndexGraph newFromBuilder(IndexGraphBuilderImpl builder) { } }; }; - MutableImpl hashtableMultiImpl = hashtableMultiImplFactory.get(false); - MutableImpl hashtableMultiImplWithSelfEdges = hashtableMultiImplFactory.get(true); - Boolean2ObjectFunction matrixImplFactory = selfEdges -> { + MutableImpl hashtableMultiImpl = hashtableMultiImplFactory.apply(false); + MutableImpl hashtableMultiImplWithSelfEdges = hashtableMultiImplFactory.apply(true); + Function matrixImplFactory = selfEdges -> { return directed ? new MutableImpl() { @Override @@ -311,8 +312,8 @@ public IndexGraph newFromBuilder(IndexGraphBuilderImpl builder) { } }; }; - MutableImpl matrixImpl = matrixImplFactory.get(false); - MutableImpl matrixImplWithSelfEdges = matrixImplFactory.get(true); + MutableImpl matrixImpl = matrixImplFactory.apply(false); + MutableImpl matrixImplWithSelfEdges = matrixImplFactory.apply(true); if (impl != null) { switch (impl) { @@ -377,8 +378,9 @@ IndexGraphBuilder.ReIndexedGraph newFromBuilderWithReIndex(IndexGraphBuilderImpl } + @SuppressWarnings("boxing") ImmutableImpl immutableImpl() { - Boolean2ObjectFunction csrImplFactory = fastLookup -> { + Function csrImplFactory = fastLookup -> { return directed ? new ImmutableImpl() { @Override public IndexGraph newCopyOf(IndexGraph graph, boolean copyVerticesWeights, boolean copyEdgesWeights) { @@ -450,8 +452,8 @@ public ReIndexedGraph newFromBuilderWithReIndex(IndexGraphBuilderImpl builder, b } }; }; - ImmutableImpl csrImpl = csrImplFactory.get(false); - ImmutableImpl csrImplWithFastLookup = csrImplFactory.get(true); + ImmutableImpl csrImpl = csrImplFactory.apply(false); + ImmutableImpl csrImplWithFastLookup = csrImplFactory.apply(true); if (hints.contains(GraphFactory.Hint.FastEdgeLookup)) { return csrImplWithFastLookup; } else { diff --git a/jgalgo-core/src/main/java/com/jgalgo/internal/ds/RMQStaticLinearAbstract.java b/jgalgo-core/src/main/java/com/jgalgo/internal/ds/RMQStaticLinearAbstract.java index 4bd75571a5..2363863666 100644 --- a/jgalgo-core/src/main/java/com/jgalgo/internal/ds/RMQStaticLinearAbstract.java +++ b/jgalgo-core/src/main/java/com/jgalgo/internal/ds/RMQStaticLinearAbstract.java @@ -17,12 +17,8 @@ package com.jgalgo.internal.ds; import com.jgalgo.internal.util.Bitmap; -import it.unimi.dsi.fastutil.bytes.Byte2IntMap; -import it.unimi.dsi.fastutil.bytes.Byte2IntOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2IntMap; import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; -import it.unimi.dsi.fastutil.shorts.Short2IntMap; -import it.unimi.dsi.fastutil.shorts.Short2IntOpenHashMap; abstract class RMQStaticLinearAbstract implements RMQStatic { @@ -81,78 +77,31 @@ abstract class PreProcessor extends DsBase { } void preProcessInnerBlocks() { - int keySize = getBlockKeySize(); var innerBlocksIdx = new Object() { int val = 0; }; blockToInnerIdx = new int[blockNum]; final int innerBlockAllocSize = blockSize * (blockSize - 1) / 2; - if (keySize < Byte.SIZE) { - Byte2IntMap tables = new Byte2IntOpenHashMap(); - for (int b = 0; b < blockNum; b++) { - byte key = (byte) calcBlockKey(b); - blockToInnerIdx[b] = key; - tables.computeIfAbsent(key, k -> innerBlocksIdx.val++); - } - final int innerBlockNum = tables.size(); - Bitmap builtInnerBlocks = new Bitmap(innerBlockNum); - innerBlocks = new byte[innerBlockNum * innerBlockAllocSize]; - for (int b = 0; b < blockNum; b++) { - byte key = (byte) blockToInnerIdx[b]; - int innerIdx = tables.get(key); - blockToInnerIdx[b] = innerIdx; - if (!builtInnerBlocks.get(innerIdx)) { - byte[] demoBlock = calcDemoBlock(key & 0xff); - buildInnerBlock(innerIdx, demoBlock); - builtInnerBlocks.set(innerIdx); - } - } - tables.clear(); - - } else if (keySize < Short.SIZE) { - Short2IntMap tables = new Short2IntOpenHashMap(); - for (int b = 0; b < blockNum; b++) { - short key = (short) calcBlockKey(b); - blockToInnerIdx[b] = key; - tables.computeIfAbsent(key, k -> innerBlocksIdx.val++); - } - final int innerBlockNum = tables.size(); - Bitmap builtInnerBlocks = new Bitmap(innerBlockNum); - innerBlocks = new byte[innerBlockNum * innerBlockAllocSize]; - for (int b = 0; b < blockNum; b++) { - short key = (short) blockToInnerIdx[b]; - int innerIdx = tables.get(key); - blockToInnerIdx[b] = innerIdx; - if (!builtInnerBlocks.get(innerIdx)) { - byte[] demoBlock = calcDemoBlock(key & 0xffff); - buildInnerBlock(innerIdx, demoBlock); - builtInnerBlocks.set(innerIdx); - } - } - tables.clear(); - - } else { - Int2IntMap tables = new Int2IntOpenHashMap(); - for (int b = 0; b < blockNum; b++) { - int key = calcBlockKey(b); - blockToInnerIdx[b] = key; - tables.computeIfAbsent(key, k -> innerBlocksIdx.val++); - } - final int innerBlockNum = tables.size(); - Bitmap builtInnerBlocks = new Bitmap(innerBlockNum); - innerBlocks = new byte[innerBlockNum * innerBlockAllocSize]; - for (int b = 0; b < blockNum; b++) { - int key = blockToInnerIdx[b]; - int innerIdx = tables.get(key); - blockToInnerIdx[b] = innerIdx; - if (!builtInnerBlocks.get(innerIdx)) { - byte[] demoBlock = calcDemoBlock(key); - buildInnerBlock(innerIdx, demoBlock); - builtInnerBlocks.set(innerIdx); - } + Int2IntMap tables = new Int2IntOpenHashMap(); + for (int b = 0; b < blockNum; b++) { + int key = calcBlockKey(b); + blockToInnerIdx[b] = key; + tables.computeIfAbsent(key, k -> innerBlocksIdx.val++); + } + final int innerBlockNum = tables.size(); + Bitmap builtInnerBlocks = new Bitmap(innerBlockNum); + innerBlocks = new byte[innerBlockNum * innerBlockAllocSize]; + for (int b = 0; b < blockNum; b++) { + int key = blockToInnerIdx[b]; + int innerIdx = tables.get(key); + blockToInnerIdx[b] = innerIdx; + if (!builtInnerBlocks.get(innerIdx)) { + byte[] demoBlock = calcDemoBlock(key); + buildInnerBlock(innerIdx, demoBlock); + builtInnerBlocks.set(innerIdx); } - tables.clear(); } + tables.clear(); } private void buildInnerBlock(int innerBlock, byte[] demoBlock) { diff --git a/jgalgo-core/src/main/java/com/jgalgo/internal/util/Assertions.java b/jgalgo-core/src/main/java/com/jgalgo/internal/util/Assertions.java index b859ac0217..afab4531b8 100644 --- a/jgalgo-core/src/main/java/com/jgalgo/internal/util/Assertions.java +++ b/jgalgo-core/src/main/java/com/jgalgo/internal/util/Assertions.java @@ -35,10 +35,10 @@ import com.jgalgo.internal.ds.Heap; import com.jgalgo.internal.ds.ReferenceableHeap; import it.unimi.dsi.fastutil.doubles.DoubleComparator; -import it.unimi.dsi.fastutil.ints.Int2ByteMap; -import it.unimi.dsi.fastutil.ints.Int2ByteOpenHashMap; import it.unimi.dsi.fastutil.ints.IntCollection; import it.unimi.dsi.fastutil.ints.IntComparator; +import it.unimi.dsi.fastutil.ints.IntOpenHashSet; +import it.unimi.dsi.fastutil.ints.IntSet; public class Assertions { private Assertions() {} @@ -176,24 +176,31 @@ public static void sourcesSinksNotTheSame(IntCollection sources, IntCollection s throw new IllegalArgumentException("no sources vertices provided"); if (sinks.isEmpty()) throw new IllegalArgumentException("no sinks vertices provided"); - final byte UNSEEN = 0; - final byte SOURCE = 1; - final byte TARGET = 2; - Int2ByteMap types = new Int2ByteOpenHashMap(sources.size() + sinks.size()); - types.defaultReturnValue(UNSEEN); - for (int v : sources) { - int vType = types.put(v, SOURCE); - if (vType != UNSEEN) - throw new IllegalArgumentException("Source vertex appear twice (idx=" + v + ")"); + IntSet sourcesSet; + if (sources instanceof IntSet) { + sourcesSet = (IntSet) sources; + } else { + sourcesSet = new IntOpenHashSet(sources.size()); + for (int v : sources) { + boolean added = sourcesSet.add(v); + if (!added) + throw new IllegalArgumentException("Source vertex appear twice (idx=" + v + ")"); + } } - for (int v : sinks) { - int vType = types.put(v, TARGET); - if (vType != UNSEEN) { - if (vType == SOURCE) + if (sinks instanceof IntSet) { + for (int sink : sinks) { + if (sourcesSet.contains(sink)) throw new IllegalArgumentException( - "A vertex can't be both a source and target (idx=" + v + ")"); - if (vType == TARGET) - throw new IllegalArgumentException("Target vertex appear twice (idx=" + v + ")"); + "A vertex can't be both a source and sink (idx=" + sink + ")"); + } + } else { + IntSet verticesSet = new IntOpenHashSet(sinks.size()); + for (int v : sinks) { + boolean added = verticesSet.add(v); + if (!added) + throw new IllegalArgumentException("Sink vertex appear twice (idx=" + v + ")"); + if (sourcesSet.contains(v)) + throw new IllegalArgumentException("A vertex can't be both a source and sink (idx=" + v + ")"); } } } diff --git a/jgalgo-core/src/test/java/com/jgalgo/alg/MatchingBipartiteTestUtils.java b/jgalgo-core/src/test/java/com/jgalgo/alg/MatchingBipartiteTestUtils.java index 22afffaf83..db4e12880c 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/alg/MatchingBipartiteTestUtils.java +++ b/jgalgo-core/src/test/java/com/jgalgo/alg/MatchingBipartiteTestUtils.java @@ -19,12 +19,12 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Objects; import java.util.Random; +import java.util.function.Function; import com.jgalgo.graph.EdgeIter; import com.jgalgo.graph.Graph; import com.jgalgo.graph.GraphsTestUtils; import com.jgalgo.graph.WeightsBool; import com.jgalgo.internal.util.TestUtils; -import it.unimi.dsi.fastutil.booleans.Boolean2ObjectFunction; import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; @@ -36,7 +36,8 @@ static void randBipartiteGraphs(MatchingAlgo algo, long seed) { randBipartiteGraphs(algo, GraphsTestUtils.defaultGraphImpl(seed), seed); } - public static void randBipartiteGraphs(MatchingAlgo algo, Boolean2ObjectFunction> graphImpl, + @SuppressWarnings("boxing") + public static void randBipartiteGraphs(MatchingAlgo algo, Function> graphImpl, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); @@ -47,7 +48,7 @@ public static void randBipartiteGraphs(MatchingAlgo algo, Boolean2ObjectFunction tester.addPhase().withArgs(128, 128, 512).repeat(8); tester.addPhase().withArgs(300, 300, 1100).repeat(1); tester.run((sn, tn, m) -> { - boolean parallelEdges = graphImpl.get(false).isAllowParallelEdges(); + boolean parallelEdges = graphImpl.apply(false).isAllowParallelEdges(); Graph g = GraphsTestUtils .withImpl(GraphsTestUtils.randBipartiteGraph(sn, tn, m, false, parallelEdges, seedGen.nextSeed()), graphImpl); diff --git a/jgalgo-core/src/test/java/com/jgalgo/alg/MatchingWeightedTestUtils.java b/jgalgo-core/src/test/java/com/jgalgo/alg/MatchingWeightedTestUtils.java index 37f732fb1b..c733811cba 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/alg/MatchingWeightedTestUtils.java +++ b/jgalgo-core/src/test/java/com/jgalgo/alg/MatchingWeightedTestUtils.java @@ -20,6 +20,7 @@ import java.util.Collections; import java.util.List; import java.util.Random; +import java.util.function.Function; import java.util.function.Supplier; import com.jgalgo.graph.Graph; import com.jgalgo.graph.GraphsTestUtils; @@ -27,7 +28,6 @@ import com.jgalgo.graph.WeightFunctionInt; import com.jgalgo.graph.WeightsBool; import com.jgalgo.internal.util.TestUtils; -import it.unimi.dsi.fastutil.booleans.Boolean2ObjectFunction; import it.unimi.dsi.fastutil.ints.IntArrayList; public class MatchingWeightedTestUtils extends TestUtils { @@ -39,7 +39,7 @@ static void randGraphsBipartiteWeighted(MatchingAlgo algo, long seed) { } public static void randGraphsBipartiteWeighted(MatchingAlgo algo, - Boolean2ObjectFunction> graphImpl, long seed) { + Function> graphImpl, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); PhasedTester tester = new PhasedTester(); @@ -48,7 +48,7 @@ public static void randGraphsBipartiteWeighted(MatchingAlgo algo, tester.addPhase().withArgs(128, 128, 128).repeat(12); tester.addPhase().withArgs(256, 256, 1200).repeat(2); tester.run((sn, tn, m) -> { - boolean parallelEdges = graphImpl.get(false).isAllowParallelEdges(); + boolean parallelEdges = graphImpl.apply(Boolean.FALSE).isAllowParallelEdges(); Graph g = GraphsTestUtils .withImpl(GraphsTestUtils.randBipartiteGraph(sn, tn, m, false, parallelEdges, seedGen.nextSeed()), graphImpl); diff --git a/jgalgo-core/src/test/java/com/jgalgo/alg/MaximumFlowTestUtils.java b/jgalgo-core/src/test/java/com/jgalgo/alg/MaximumFlowTestUtils.java index 78463da1d6..1d8ad1ade3 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/alg/MaximumFlowTestUtils.java +++ b/jgalgo-core/src/test/java/com/jgalgo/alg/MaximumFlowTestUtils.java @@ -24,6 +24,7 @@ import java.util.Random; import java.util.Set; import java.util.TreeSet; +import java.util.function.Function; import com.jgalgo.graph.EdgeIter; import com.jgalgo.graph.Graph; import com.jgalgo.graph.Graphs; @@ -35,7 +36,6 @@ import com.jgalgo.graph.WeightsInt; import com.jgalgo.internal.util.TestUtils; import it.unimi.dsi.fastutil.Pair; -import it.unimi.dsi.fastutil.booleans.Boolean2ObjectFunction; import it.unimi.dsi.fastutil.objects.Object2DoubleMap; import it.unimi.dsi.fastutil.objects.Object2DoubleOpenHashMap; import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; @@ -50,9 +50,9 @@ private static Graph randGraph(int n, int m, long seed, boolea directed); } - private static Graph randGraph(int n, int m, - Boolean2ObjectFunction> graphImpl, long seed, boolean directed) { - boolean selfEdges = graphImpl.get(directed).isAllowSelfEdges(); + private static Graph randGraph(int n, int m, Function> graphImpl, + long seed, boolean directed) { + boolean selfEdges = graphImpl.apply(directed).isAllowSelfEdges(); for (SeedGenerator seedGen = new SeedGenerator(seed);;) { Graph g = GraphsTestUtils .withImpl(GraphsTestUtils.randGraph(n, m, directed, selfEdges, false, seedGen.nextSeed()), @@ -108,8 +108,8 @@ static void testRandGraphsInt(MaximumFlow algo, long seed, boolean directed) { testRandGraphsInt(algo, GraphsTestUtils.defaultGraphImpl(seed), seed, directed); } - public static void testRandGraphs(MaximumFlow algo, Boolean2ObjectFunction> graphImpl, - long seed, boolean directed) { + public static void testRandGraphs(MaximumFlow algo, Function> graphImpl, long seed, + boolean directed) { final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); PhasedTester tester = new PhasedTester(); @@ -155,8 +155,8 @@ public static void testRandGraphsMultiSourceMultiSink(MaximumFlow algo, long see }); } - static void testRandGraphsInt(MaximumFlow algo, Boolean2ObjectFunction> graphImpl, - long seed, boolean directed) { + static void testRandGraphsInt(MaximumFlow algo, Function> graphImpl, long seed, + boolean directed) { final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); PhasedTester tester = new PhasedTester(); diff --git a/jgalgo-core/src/test/java/com/jgalgo/alg/MinimumDirectedSpanningTreeTarjanTest.java b/jgalgo-core/src/test/java/com/jgalgo/alg/MinimumDirectedSpanningTreeTarjanTest.java index 08dc0afb1d..8bc5b7e7a3 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/alg/MinimumDirectedSpanningTreeTarjanTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/alg/MinimumDirectedSpanningTreeTarjanTest.java @@ -20,6 +20,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Iterator; import java.util.Random; +import java.util.function.Function; import org.junit.jupiter.api.Test; import com.jgalgo.graph.EdgeIter; import com.jgalgo.graph.Graph; @@ -31,7 +32,6 @@ import com.jgalgo.graph.WeightFunction; import com.jgalgo.graph.WeightFunctionInt; import com.jgalgo.internal.util.TestBase; -import it.unimi.dsi.fastutil.booleans.Boolean2ObjectFunction; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntCollection; import it.unimi.dsi.fastutil.ints.IntIterator; @@ -116,9 +116,10 @@ public void testRandGraphDirected() { testRandGraph(new MinimumDirectedSpanningTreeTarjan(), GraphsTestUtils.defaultGraphImpl(seed), seed); } + @SuppressWarnings("boxing") public static void testRandGraph(MinimumDirectedSpanningTree algo, - Boolean2ObjectFunction> graphImpl, long seed) { - boolean selfEdges = graphImpl.get(true).isAllowSelfEdges(); + Function> graphImpl, long seed) { + boolean selfEdges = graphImpl.apply(true).isAllowSelfEdges(); final SeedGenerator seedGen = new SeedGenerator(seed); final Random rand = new Random(seedGen.nextSeed()); PhasedTester tester = new PhasedTester(); diff --git a/jgalgo-core/src/test/java/com/jgalgo/alg/MinimumSpanningTreeTestUtils.java b/jgalgo-core/src/test/java/com/jgalgo/alg/MinimumSpanningTreeTestUtils.java index 24509df964..542b5b74ea 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/alg/MinimumSpanningTreeTestUtils.java +++ b/jgalgo-core/src/test/java/com/jgalgo/alg/MinimumSpanningTreeTestUtils.java @@ -21,6 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Comparator; import java.util.Set; +import java.util.function.Function; import com.jgalgo.graph.Graph; import com.jgalgo.graph.GraphsTestUtils; import com.jgalgo.graph.IndexIdMap; @@ -28,7 +29,6 @@ import com.jgalgo.graph.WeightFunction; import com.jgalgo.graph.WeightFunctionInt; import com.jgalgo.internal.util.TestUtils; -import it.unimi.dsi.fastutil.booleans.Boolean2ObjectFunction; import it.unimi.dsi.fastutil.objects.ObjectAVLTreeSet; public class MinimumSpanningTreeTestUtils extends TestUtils { @@ -39,8 +39,9 @@ static void testRandGraph(MinimumSpanningTree algo, long seed) { testRandGraph(algo, GraphsTestUtils.defaultGraphImpl(seed), seed); } - public static void testRandGraph(MinimumSpanningTree algo, - Boolean2ObjectFunction> graphImpl, long seed) { + @SuppressWarnings("boxing") + public static void testRandGraph(MinimumSpanningTree algo, Function> graphImpl, + long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); PhasedTester tester = new PhasedTester(); tester.addPhase().withArgs(16, 32).repeat(128); @@ -49,8 +50,8 @@ public static void testRandGraph(MinimumSpanningTree algo, tester.addPhase().withArgs(1024, 4096).repeat(8); tester.addPhase().withArgs(4096, 16384).repeat(2); tester.run((n, m) -> { - boolean selfEdges = graphImpl.get(false).isAllowSelfEdges(); - boolean parallelEdges = graphImpl.get(false).isAllowParallelEdges(); + boolean selfEdges = graphImpl.apply(false).isAllowSelfEdges(); + boolean parallelEdges = graphImpl.apply(false).isAllowParallelEdges(); Graph g = GraphsTestUtils .withImpl(GraphsTestUtils.randGraph(n, m, false, selfEdges, parallelEdges, seedGen.nextSeed()), graphImpl); diff --git a/jgalgo-core/src/test/java/com/jgalgo/alg/VertexBiPartitionTest.java b/jgalgo-core/src/test/java/com/jgalgo/alg/VertexBiPartitionTest.java index 11494b3a4a..c7002f54a8 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/alg/VertexBiPartitionTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/alg/VertexBiPartitionTest.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.Random; import java.util.Set; import java.util.stream.Collectors; @@ -29,8 +30,7 @@ import com.jgalgo.graph.Graph; import com.jgalgo.graph.GraphsTestUtils; import com.jgalgo.internal.util.TestBase; -import it.unimi.dsi.fastutil.objects.Object2BooleanMap; -import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; public class VertexBiPartitionTest extends TestBase { @@ -152,8 +152,8 @@ public void testIsPartition() { foreachBoolConfig((directed, index) -> { Graph g = randGraph(n, m, directed, index, seedGen.nextSeed()); - Object2BooleanMap partition = randPartitionMap(g, seedGen.nextSeed()); - assertTrue(VertexBiPartition.isPartition(g, partition::getBoolean)); + Map partition = randPartitionMap(g, seedGen.nextSeed()); + assertTrue(VertexBiPartition.isPartition(g, partition::get)); assertFalse(VertexBiPartition.isPartition(g, v -> true)); assertFalse(VertexBiPartition.isPartition(g, v -> false)); @@ -165,13 +165,14 @@ private static VertexBiPartition randPartition(Graph g, long return VertexBiPartition.fromMap(g, randPartitionMap(g, seed)); } - private static Object2BooleanMap randPartitionMap(Graph g, long seed) { + @SuppressWarnings("boxing") + private static Map randPartitionMap(Graph g, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); final Random rand = new Random(seedGen.nextSeed()); final int n = g.vertices().size(); if (2 > n) throw new IllegalArgumentException(); - Object2BooleanMap partition = new Object2BooleanOpenHashMap<>(); + Map partition = new Object2ObjectOpenHashMap<>(); List vs = new ArrayList<>(g.vertices()); Collections.shuffle(vs, rand); diff --git a/jgalgo-core/src/test/java/com/jgalgo/graph/GraphArrayTest.java b/jgalgo-core/src/test/java/com/jgalgo/graph/GraphArrayTest.java index 03f4c479b0..6f24f97c9c 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/graph/GraphArrayTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/graph/GraphArrayTest.java @@ -17,15 +17,15 @@ package com.jgalgo.graph; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.util.function.Function; import org.junit.jupiter.api.Test; import com.jgalgo.internal.util.TestBase; -import it.unimi.dsi.fastutil.booleans.Boolean2ObjectFunction; public class GraphArrayTest extends TestBase { - private static Boolean2ObjectFunction> graphImpl(boolean selfEdges) { + private static Function> graphImpl(boolean selfEdges) { return directed -> IntGraphFactory - .newInstance(directed) + .newInstance(directed.booleanValue()) .setOption("impl", selfEdges ? "array-selfedges" : "array") .newGraph(); } diff --git a/jgalgo-core/src/test/java/com/jgalgo/graph/GraphBuilderTest.java b/jgalgo-core/src/test/java/com/jgalgo/graph/GraphBuilderTest.java index c1f6f52c76..94f7696f7e 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/graph/GraphBuilderTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/graph/GraphBuilderTest.java @@ -37,7 +37,6 @@ import org.junit.jupiter.api.Test; import com.jgalgo.internal.util.TestBase; import it.unimi.dsi.fastutil.Pair; -import it.unimi.dsi.fastutil.booleans.BooleanList; import it.unimi.dsi.fastutil.ints.IntList; public class GraphBuilderTest extends TestBase { @@ -359,7 +358,7 @@ public void build() { AtomicInteger weightIdx = new AtomicInteger(); @SuppressWarnings("rawtypes") BiConsumer addWeights = (type, valSupplier) -> { - for (boolean edgesWeights : BooleanList.of(false, true)) { + foreachBoolConfig(edgesWeights -> { for (int repeat = 1 + rand.nextInt(2); repeat > 0; repeat--) { String key = "weight" + weightIdx.getAndIncrement(); Object defVal = rand.nextBoolean() ? valSupplier.get() : null; @@ -390,7 +389,7 @@ public void build() { wB.setAsObj(elm, w); } } - } + }); }; addWeights.accept(byte.class, () -> Byte.valueOf((byte) rand.nextInt())); addWeights.accept(short.class, () -> Short.valueOf((short) rand.nextInt())); diff --git a/jgalgo-core/src/test/java/com/jgalgo/graph/GraphHashmapMultiTest.java b/jgalgo-core/src/test/java/com/jgalgo/graph/GraphHashmapMultiTest.java index 3936924eee..eb86176d9d 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/graph/GraphHashmapMultiTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/graph/GraphHashmapMultiTest.java @@ -17,15 +17,15 @@ package com.jgalgo.graph; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.util.function.Function; import org.junit.jupiter.api.Test; import com.jgalgo.internal.util.TestBase; -import it.unimi.dsi.fastutil.booleans.Boolean2ObjectFunction; public class GraphHashmapMultiTest extends TestBase { - private static Boolean2ObjectFunction> graphImpl(boolean selfEdges) { + private static Function> graphImpl(boolean selfEdges) { return directed -> IntGraphFactory - .newInstance(directed) + .newInstance(directed.booleanValue()) .setOption("impl", selfEdges ? "hashtable-multi-selfedges" : "hashtable-multi") .newGraph(); } diff --git a/jgalgo-core/src/test/java/com/jgalgo/graph/GraphHashmapTest.java b/jgalgo-core/src/test/java/com/jgalgo/graph/GraphHashmapTest.java index 5cca501073..69654b3857 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/graph/GraphHashmapTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/graph/GraphHashmapTest.java @@ -17,15 +17,15 @@ package com.jgalgo.graph; import static org.junit.jupiter.api.Assertions.assertFalse; +import java.util.function.Function; import org.junit.jupiter.api.Test; import com.jgalgo.internal.util.TestBase; -import it.unimi.dsi.fastutil.booleans.Boolean2ObjectFunction; public class GraphHashmapTest extends TestBase { - private static Boolean2ObjectFunction> graphImpl(boolean selfEdges) { + private static Function> graphImpl(boolean selfEdges) { return directed -> IntGraphFactory - .newInstance(directed) + .newInstance(directed.booleanValue()) .setOption("impl", selfEdges ? "hashtable-selfedges" : "hashtable") .newGraph(); } diff --git a/jgalgo-core/src/test/java/com/jgalgo/graph/GraphImplTest.java b/jgalgo-core/src/test/java/com/jgalgo/graph/GraphImplTest.java index 8052ca2ff0..4f502c8b98 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/graph/GraphImplTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/graph/GraphImplTest.java @@ -27,9 +27,9 @@ import java.util.List; import java.util.Random; import java.util.Set; +import java.util.function.Function; import org.junit.jupiter.api.Test; import com.jgalgo.internal.util.TestBase; -import it.unimi.dsi.fastutil.booleans.Boolean2ObjectFunction; import it.unimi.dsi.fastutil.ints.IntOpenHashSet; public class GraphImplTest extends TestBase { @@ -248,8 +248,11 @@ public void removeEdges() { }); } - private static Boolean2ObjectFunction> graphImpl(boolean selfEdges) { - return directed -> GraphFactory.newInstance(directed).allowSelfEdges(selfEdges).newGraph(); + private static Function> graphImpl(boolean selfEdges) { + return directed -> GraphFactory + .newInstance(directed.booleanValue()) + .allowSelfEdges(selfEdges) + .newGraph(); } @Test diff --git a/jgalgo-core/src/test/java/com/jgalgo/graph/GraphImplTestUtils.java b/jgalgo-core/src/test/java/com/jgalgo/graph/GraphImplTestUtils.java index 6cbba35263..1ed4d03ce7 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/graph/GraphImplTestUtils.java +++ b/jgalgo-core/src/test/java/com/jgalgo/graph/GraphImplTestUtils.java @@ -56,7 +56,6 @@ import com.jgalgo.alg.MinimumSpanningTreeTestUtils; import com.jgalgo.internal.util.TestUtils; import it.unimi.dsi.fastutil.Pair; -import it.unimi.dsi.fastutil.booleans.Boolean2ObjectFunction; import it.unimi.dsi.fastutil.ints.AbstractIntSet; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; @@ -76,6 +75,7 @@ import it.unimi.dsi.fastutil.objects.ObjectSet; import it.unimi.dsi.fastutil.objects.ObjectSets; +@SuppressWarnings("boxing") class GraphImplTestUtils extends TestUtils { @SafeVarargs @@ -86,10 +86,10 @@ static Set setOf(K... elms) { return ObjectSets.unmodifiable(set); } - @SuppressWarnings({ "boxing", "deprecation" }) - static void testAddVertex(Boolean2ObjectFunction> graphImpl) { + @SuppressWarnings("deprecation") + static void testAddVertex(Function> graphImpl) { foreachBoolConfig(directed -> { - Graph g = graphImpl.get(directed); + Graph g = graphImpl.apply(directed); final int n = 100; IntSet verticesSet = new IntOpenHashSet(); for (int i = 0; i < n; i++) { @@ -103,7 +103,7 @@ static void testAddVertex(Boolean2ObjectFunction> graphI assertThrows(NoSuchVertexException.class, () -> g.outEdges(6687)); }); foreachBoolConfig(directed -> { - IndexGraph g = graphImpl.get(directed).indexGraph(); + IndexGraph g = graphImpl.apply(directed).indexGraph(); IdBuilderInt vBuilder = g.vertexBuilder(); final int n = 87; for (int i = 0; i < n; i++) { @@ -125,15 +125,14 @@ static void testAddVertex(Boolean2ObjectFunction> graphI }); } - @SuppressWarnings("boxing") - static void addVerticesTest(Boolean2ObjectFunction> graphImpl) { + static void addVerticesTest(Function> graphImpl) { final Random rand = new Random(0x4a4735619a4c9042L); /* addVertices() valid */ foreachBoolConfig(directed -> { for (int repeat = 0; repeat < 25; repeat++) { final int n = rand.nextInt(100); - Graph g = graphImpl.get(directed); + Graph g = graphImpl.apply(directed); Set vertices = new IntOpenHashSet(); while (vertices.size() < n) { @@ -156,7 +155,7 @@ static void addVerticesTest(Boolean2ObjectFunction> grap foreachBoolConfig(directed -> { for (int repeat = 0; repeat < 25; repeat++) { final int n = rand.nextInt(100); - Graph g = graphImpl.get(directed); + Graph g = graphImpl.apply(directed); Set vertices = new IntOpenHashSet(); while (vertices.size() < n) { @@ -185,7 +184,7 @@ static void addVerticesTest(Boolean2ObjectFunction> grap foreachBoolConfig(directed -> { for (int repeat = 0; repeat < 25; repeat++) { final int n = rand.nextInt(100); - Graph g = graphImpl.get(directed); + Graph g = graphImpl.apply(directed); Set vertices = new IntOpenHashSet(); while (vertices.size() < n) { @@ -214,7 +213,7 @@ static void addVerticesTest(Boolean2ObjectFunction> grap foreachBoolConfig(directed -> { for (int repeat = 0; repeat < 25; repeat++) { final int n = rand.nextInt(100); - Graph g = graphImpl.get(directed); + Graph g = graphImpl.apply(directed); Set vertices = new IntOpenHashSet(); while (vertices.size() < n) { @@ -243,7 +242,7 @@ static void addVerticesTest(Boolean2ObjectFunction> grap foreachBoolConfig(directed -> { for (int repeat = 0; repeat < 25; repeat++) { final int n = rand.nextInt(100); - IndexGraph g = graphImpl.get(directed).indexGraph(); + IndexGraph g = graphImpl.apply(directed).indexGraph(); int verticesNum = 0; while (verticesNum < n) { @@ -259,7 +258,7 @@ static void addVerticesTest(Boolean2ObjectFunction> grap foreachBoolConfig(directed -> { for (int repeat = 0; repeat < 25; repeat++) { final int n = rand.nextInt(100); - IndexGraph g = graphImpl.get(directed).indexGraph(); + IndexGraph g = graphImpl.apply(directed).indexGraph(); int verticesNum = 0; while (verticesNum < n) { @@ -280,7 +279,7 @@ static void addVerticesTest(Boolean2ObjectFunction> grap foreachBoolConfig(directed -> { for (int repeat = 0; repeat < 25; repeat++) { final int n = rand.nextInt(100); - IndexGraph g = graphImpl.get(directed).indexGraph(); + IndexGraph g = graphImpl.apply(directed).indexGraph(); int verticesNum = 0; while (verticesNum < n) { @@ -306,7 +305,7 @@ static void addVerticesTest(Boolean2ObjectFunction> grap foreachBoolConfig(directed -> { for (int repeat = 0; repeat < 25; repeat++) { final int n = rand.nextInt(100); - IndexGraph g = graphImpl.get(directed).indexGraph(); + IndexGraph g = graphImpl.apply(directed).indexGraph(); int verticesNum = 0; while (verticesNum < n) { @@ -323,7 +322,7 @@ static void addVerticesTest(Boolean2ObjectFunction> grap foreachBoolConfig(directed -> { for (int repeat = 0; repeat < 25; repeat++) { final int n = rand.nextInt(100); - IndexGraph g = graphImpl.get(directed).indexGraph(); + IndexGraph g = graphImpl.apply(directed).indexGraph(); int verticesNum = 0; while (verticesNum < n) { @@ -341,7 +340,7 @@ static void addVerticesTest(Boolean2ObjectFunction> grap foreachBoolConfig(directed -> { for (int repeat = 0; repeat < 25; repeat++) { final int n = rand.nextInt(100); - IndexGraph g = graphImpl.get(directed).indexGraph(); + IndexGraph g = graphImpl.apply(directed).indexGraph(); int verticesNum = 0; while (verticesNum < n) { @@ -366,7 +365,7 @@ static void addVerticesTest(Boolean2ObjectFunction> grap foreachBoolConfig(directed -> { for (int repeat = 0; repeat < 25; repeat++) { final int n = rand.nextInt(100); - IndexGraph g = graphImpl.get(directed).indexGraph(); + IndexGraph g = graphImpl.apply(directed).indexGraph(); int verticesNum = 0; while (verticesNum < n) { @@ -391,7 +390,7 @@ static void addVerticesTest(Boolean2ObjectFunction> grap foreachBoolConfig(directed -> { for (int repeat = 0; repeat < 25; repeat++) { final int n = rand.nextInt(100); - IndexGraph g = graphImpl.get(directed).indexGraph(); + IndexGraph g = graphImpl.apply(directed).indexGraph(); int verticesNum = 0; while (verticesNum < n) { @@ -418,11 +417,11 @@ static void addVerticesTest(Boolean2ObjectFunction> grap }); } - static void removeVerticesTest(Boolean2ObjectFunction> graphImpl) { + static void removeVerticesTest(Function> graphImpl) { final Random rand = new Random(0x36f43a2a1e51d79dL); - Boolean2ObjectFunction> createGraph = directed -> { - Graph g = graphImpl.get(directed); + Function> createGraph = directed -> { + Graph g = graphImpl.apply(directed); g.addVertices(range(50 + rand.nextInt(100))); final int m = 100 + rand.nextInt(100); while (g.edges().size() < m) { @@ -444,7 +443,7 @@ static void removeVerticesTest(Boolean2ObjectFunction> g /* removeVertices() valid */ foreachBoolConfig(directed -> { for (int repeat = 0; repeat < 25; repeat++) { - Graph g = createGraph.get(directed); + Graph g = createGraph.apply(directed); Graph expectedGraph = g.copy(); Set vertices = new IntOpenHashSet(expectedGraph.vertices()); @@ -466,7 +465,7 @@ static void removeVerticesTest(Boolean2ObjectFunction> g /* removeVertices() sometimes with duplicate vertex (in removed list) */ foreachBoolConfig(directed -> { for (int repeat = 0; repeat < 25; repeat++) { - Graph g = createGraph.get(directed); + Graph g = createGraph.apply(directed); Graph expectedGraph = g.copy(); Set vertices = new IntOpenHashSet(expectedGraph.vertices()); @@ -495,7 +494,7 @@ static void removeVerticesTest(Boolean2ObjectFunction> g /* removeVertices() sometimes with non existing vertex */ foreachBoolConfig(directed -> { for (int repeat = 0; repeat < 25; repeat++) { - Graph g = createGraph.get(directed); + Graph g = createGraph.apply(directed); Graph expectedGraph = g.copy(); Set vertices = new IntOpenHashSet(expectedGraph.vertices()); @@ -528,7 +527,7 @@ static void removeVerticesTest(Boolean2ObjectFunction> g /* removeVertices() sometimes with null vertex */ foreachBoolConfig(directed -> { for (int repeat = 0; repeat < 25; repeat++) { - Graph g = createGraph.get(directed); + Graph g = createGraph.apply(directed); Graph expectedGraph = g.copy(); Set vertices = new IntOpenHashSet(expectedGraph.vertices()); @@ -555,10 +554,10 @@ static void removeVerticesTest(Boolean2ObjectFunction> g }); } - @SuppressWarnings({ "deprecation" }) - static void verticesTest(Boolean2ObjectFunction> graphImpl) { + @SuppressWarnings("deprecation") + static void verticesTest(Function> graphImpl) { foreachBoolConfig((directed, index) -> { - Graph g = graphImpl.get(directed); + Graph g = graphImpl.apply(directed); if (index) g = g.indexGraph(); final int n = 100; @@ -597,11 +596,11 @@ static void verticesTest(Boolean2ObjectFunction> graphIm }); } - @SuppressWarnings({ "boxing", "deprecation" }) - static void testAddEdge(Boolean2ObjectFunction> graphImpl) { + @SuppressWarnings("deprecation") + static void testAddEdge(Function> graphImpl) { foreachBoolConfig(directed -> { final int n = 100; - Graph g = graphImpl.get(directed); + Graph g = graphImpl.apply(directed); g.addVertices(range(1, n + 1)); List vs = new ArrayList<>(g.vertices()); @@ -625,7 +624,7 @@ static void testAddEdge(Boolean2ObjectFunction> graphImp }); foreachBoolConfig(directed -> { final int n = 100; - IndexGraph g = graphImpl.get(directed).indexGraph(); + IndexGraph g = graphImpl.apply(directed).indexGraph(); g.addVertices(range(n)); IdBuilderInt eBuilder = g.edgeBuilder(); for (int i = 0; i < n; i++) { @@ -639,7 +638,7 @@ static void testAddEdge(Boolean2ObjectFunction> graphImp }); foreachBoolConfig(directed -> { - Graph g = graphImpl.get(directed); + Graph g = graphImpl.apply(directed); if (!g.isAllowSelfEdges()) { g.addVertex(0); assertThrows(IllegalArgumentException.class, () -> g.addEdge(0, 0, 0)); @@ -647,7 +646,7 @@ static void testAddEdge(Boolean2ObjectFunction> graphImp }); foreachBoolConfig(directed -> { - Graph g = graphImpl.get(directed); + Graph g = graphImpl.apply(directed); if (!g.isAllowParallelEdges()) { g.addVertex(0); g.addVertex(1); @@ -658,7 +657,7 @@ static void testAddEdge(Boolean2ObjectFunction> graphImp } }); foreachBoolConfig(directed -> { - IndexGraph g = graphImpl.get(directed).indexGraph(); + IndexGraph g = graphImpl.apply(directed).indexGraph(); final int n = 87; for (int i = 0; i < n; i++) g.addVertexInt(); @@ -762,7 +761,6 @@ public int size() { return ids.size(); } - @SuppressWarnings("boxing") @Override public IEdgeIter iterator() { return new IEdgeIter() { @@ -877,13 +875,13 @@ private static void assertExpectedEdges(Map> exp } } - static void addEdgesTest(Boolean2ObjectFunction> graphImpl) { + static void addEdgesTest(Function> graphImpl) { final Random rand = new Random(0xa6e1e4b317a0d1c1L); /* addEdges() valid */ foreachBoolConfig((directed, index) -> { for (int repeat = 0; repeat < 25; repeat++) { - Graph g0 = graphImpl.get(directed); + Graph g0 = graphImpl.apply(directed); Graph g = index ? g0.indexGraph() : g0; g.addVertices(range(50 + rand.nextInt(100))); final int m = rand.nextInt(100); @@ -904,7 +902,7 @@ static void addEdgesTest(Boolean2ObjectFunction> graphIm /* addEdges() sometimes with duplicate edge id (in added list) */ foreachBoolConfig(directed -> { for (int repeat = 0; repeat < 25; repeat++) { - Graph g = graphImpl.get(directed); + Graph g = graphImpl.apply(directed); g.addVertices(range(50 + rand.nextInt(100))); final int m = rand.nextInt(100); @@ -932,7 +930,7 @@ static void addEdgesTest(Boolean2ObjectFunction> graphIm /* addEdges() sometimes with existing edge */ foreachBoolConfig((directed, index) -> { for (int repeat = 0; repeat < 25; repeat++) { - Graph g0 = graphImpl.get(directed); + Graph g0 = graphImpl.apply(directed); Graph g = index ? g0.indexGraph() : g0; g.addVertices(range(50 + rand.nextInt(100))); final int m = rand.nextInt(100); @@ -961,7 +959,7 @@ static void addEdgesTest(Boolean2ObjectFunction> graphIm /* addEdges() sometimes with null edge */ foreachBoolConfig((directed, index) -> { for (int repeat = 0; repeat < 25; repeat++) { - Graph g0 = graphImpl.get(directed); + Graph g0 = graphImpl.apply(directed); Graph g = index ? g0.indexGraph() : g0; g.addVertices(range(50 + rand.nextInt(100))); final int m = rand.nextInt(100); @@ -990,7 +988,7 @@ static void addEdgesTest(Boolean2ObjectFunction> graphIm /* addEdges() int graph sometimes with negative edge */ foreachBoolConfig(directed -> { for (int repeat = 0; repeat < 25; repeat++) { - Graph g0 = graphImpl.get(directed); + Graph g0 = graphImpl.apply(directed); if (!(g0 instanceof IntGraph)) return; IntGraph g = (IntGraph) g0; @@ -1021,7 +1019,7 @@ static void addEdgesTest(Boolean2ObjectFunction> graphIm /* addEdges() sometimes with invalid endpoint */ foreachBoolConfig((directed, index) -> { for (int repeat = 0; repeat < 25; repeat++) { - Graph g0 = graphImpl.get(directed); + Graph g0 = graphImpl.apply(directed); Graph g = index ? g0.indexGraph() : g0; g.addVertices(range(50 + rand.nextInt(100))); final int m = rand.nextInt(100); @@ -1058,7 +1056,7 @@ static void addEdgesTest(Boolean2ObjectFunction> graphIm /* addEdges() sometimes with self edge */ foreachBoolConfig((directed, index) -> { for (int repeat = 0; repeat < 25; repeat++) { - Graph g0 = graphImpl.get(directed); + Graph g0 = graphImpl.apply(directed); Graph g = index ? g0.indexGraph() : g0; if (g.isAllowSelfEdges()) return; @@ -1089,7 +1087,7 @@ static void addEdgesTest(Boolean2ObjectFunction> graphIm /* addEdges() sometimes with parallel edges with existing */ foreachBoolConfig((directed, index) -> { for (int repeat = 0; repeat < 25; repeat++) { - Graph g0 = graphImpl.get(directed); + Graph g0 = graphImpl.apply(directed); Graph g = index ? g0.indexGraph() : g0; if (g.isAllowParallelEdges()) return; @@ -1120,7 +1118,7 @@ static void addEdgesTest(Boolean2ObjectFunction> graphIm /* addEdges() sometimes with parallel edges in added list */ foreachBoolConfig((directed, index) -> { for (int repeat = 0; repeat < 25; repeat++) { - Graph g0 = graphImpl.get(directed); + Graph g0 = graphImpl.apply(directed); Graph g = index ? g0.indexGraph() : g0; if (g.isAllowParallelEdges()) return; @@ -1151,7 +1149,7 @@ static void addEdgesTest(Boolean2ObjectFunction> graphIm /* addEdges() index graph unsorted sometimes not in range */ foreachBoolConfig(directed -> { for (int repeat = 0; repeat < 25; repeat++) { - IndexGraph g = graphImpl.get(directed).indexGraph(); + IndexGraph g = graphImpl.apply(directed).indexGraph(); g.addVertices(range(50 + rand.nextInt(100))); final int m = rand.nextInt(100); @@ -1186,7 +1184,7 @@ static void addEdgesTest(Boolean2ObjectFunction> graphIm /* addEdges() index graph unsorted sometimes duplicate id in list */ foreachBoolConfig(directed -> { for (int repeat = 0; repeat < 25; repeat++) { - IndexGraph g = graphImpl.get(directed).indexGraph(); + IndexGraph g = graphImpl.apply(directed).indexGraph(); g.addVertices(range(50 + rand.nextInt(100))); final int m = rand.nextInt(100); @@ -1214,7 +1212,7 @@ static void addEdgesTest(Boolean2ObjectFunction> graphIm /* addEdges() index graph from EdgeSet.of() */ foreachBoolConfig((directed, fromIntGraph) -> { for (int repeat = 0; repeat < 25; repeat++) { - IndexGraph g = graphImpl.get(directed).indexGraph(); + IndexGraph g = graphImpl.apply(directed).indexGraph(); g.addVertices(range(50 + rand.nextInt(100))); final int m = rand.nextInt(100); @@ -1240,8 +1238,7 @@ static void addEdgesTest(Boolean2ObjectFunction> graphIm }); } - @SuppressWarnings("boxing") - static void addEdgesReassignIdsTest(Boolean2ObjectFunction> graphImpl) { + static void addEdgesReassignIdsTest(Function> graphImpl) { final Random rand = new Random(0x96a8f7d4731b5c5cL); BiConsumer>, IEdgeSet> addEdgesToExpected = (edgesMap, edgeSet) -> { @@ -1257,7 +1254,7 @@ static void addEdgesReassignIdsTest(Boolean2ObjectFunction { for (int repeat = 0; repeat < 25; repeat++) { - IndexGraph g = graphImpl.get(directed).indexGraph(); + IndexGraph g = graphImpl.apply(directed).indexGraph(); g.addVertices(range(50 + rand.nextInt(100))); final int m = rand.nextInt(100); @@ -1278,7 +1275,7 @@ static void addEdgesReassignIdsTest(Boolean2ObjectFunction { for (int repeat = 0; repeat < 25; repeat++) { - IndexGraph g = graphImpl.get(directed).indexGraph(); + IndexGraph g = graphImpl.apply(directed).indexGraph(); g.addVertices(range(50 + rand.nextInt(100))); final int m = rand.nextInt(100); @@ -1315,7 +1312,7 @@ static void addEdgesReassignIdsTest(Boolean2ObjectFunction { for (int repeat = 0; repeat < 25; repeat++) { - IndexGraph g = graphImpl.get(directed).indexGraph(); + IndexGraph g = graphImpl.apply(directed).indexGraph(); if (g.isAllowSelfEdges()) return; g.addVertices(range(50 + rand.nextInt(100))); @@ -1346,7 +1343,7 @@ static void addEdgesReassignIdsTest(Boolean2ObjectFunction { for (int repeat = 0; repeat < 25; repeat++) { - IndexGraph g = graphImpl.get(directed).indexGraph(); + IndexGraph g = graphImpl.apply(directed).indexGraph(); if (g.isAllowParallelEdges()) return; g.addVertices(range(50 + rand.nextInt(100))); @@ -1377,7 +1374,7 @@ static void addEdgesReassignIdsTest(Boolean2ObjectFunction { for (int repeat = 0; repeat < 25; repeat++) { - IndexGraph g = graphImpl.get(directed).indexGraph(); + IndexGraph g = graphImpl.apply(directed).indexGraph(); if (g.isAllowParallelEdges()) return; g.addVertices(range(50 + rand.nextInt(100))); @@ -1406,11 +1403,11 @@ static void addEdgesReassignIdsTest(Boolean2ObjectFunction> graphImpl) { + static void removeEdgesTest(Function> graphImpl) { final Random rand = new Random(0x9bf6ef1f132fa70eL); - Boolean2ObjectFunction> createGraph = directed -> { - Graph g = graphImpl.get(directed); + Function> createGraph = directed -> { + Graph g = graphImpl.apply(directed); g.addVertices(range(50 + rand.nextInt(100))); final int m = 100 + rand.nextInt(100); while (g.edges().size() < m) { @@ -1432,7 +1429,7 @@ static void removeEdgesTest(Boolean2ObjectFunction> grap /* removeEdges() valid */ foreachBoolConfig(directed -> { for (int repeat = 0; repeat < 25; repeat++) { - Graph g = createGraph.get(directed); + Graph g = createGraph.apply(directed); Graph expectedGraph = g.copy(); Set edges = new IntOpenHashSet(expectedGraph.edges()); @@ -1454,7 +1451,7 @@ static void removeEdgesTest(Boolean2ObjectFunction> grap /* removeEdges() sometimes with duplicate edge (in removed list) */ foreachBoolConfig(directed -> { for (int repeat = 0; repeat < 25; repeat++) { - Graph g = createGraph.get(directed); + Graph g = createGraph.apply(directed); Graph expectedGraph = g.copy(); Set edges = new IntOpenHashSet(expectedGraph.edges()); @@ -1483,7 +1480,7 @@ static void removeEdgesTest(Boolean2ObjectFunction> grap /* removeEdges() sometimes with non existing edge */ foreachBoolConfig(directed -> { for (int repeat = 0; repeat < 25; repeat++) { - Graph g = createGraph.get(directed); + Graph g = createGraph.apply(directed); Graph expectedGraph = g.copy(); Set edges = new IntOpenHashSet(expectedGraph.edges()); @@ -1516,7 +1513,7 @@ static void removeEdgesTest(Boolean2ObjectFunction> grap /* removeEdges() sometimes with null edge */ foreachBoolConfig(directed -> { for (int repeat = 0; repeat < 25; repeat++) { - Graph g = createGraph.get(directed); + Graph g = createGraph.apply(directed); Graph expectedGraph = g.copy(); Set edges = new IntOpenHashSet(expectedGraph.edges()); @@ -1544,10 +1541,10 @@ static void removeEdgesTest(Boolean2ObjectFunction> grap } @SuppressWarnings("deprecation") - static void edgesTest(Boolean2ObjectFunction> graphImpl) { + static void edgesTest(Function> graphImpl) { foreachBoolConfig((directed, index) -> { final int n = 30; - Graph g = graphImpl.get(directed); + Graph g = graphImpl.apply(directed); if (index) g = g.indexGraph(); g.addVertices(range(n)); @@ -1591,12 +1588,12 @@ static void edgesTest(Boolean2ObjectFunction> graphImpl) }); } - static void testEndpoints(Boolean2ObjectFunction> graphImpl) { + static void testEndpoints(Function> graphImpl) { final long seed = 0x62f7c169c6fbd294L; Random rand = new Random(seed); foreachBoolConfig(directed -> { final int n = 30; - Graph g = graphImpl.get(directed); + Graph g = graphImpl.apply(directed); g.addVertices(range(1, n + 1)); Map edges = new HashMap<>(); while (g.edges().size() < 60) { @@ -1628,11 +1625,11 @@ static void testEndpoints(Boolean2ObjectFunction> graphI }); } - static void getEdgeTest(Boolean2ObjectFunction> graphImpl) { + static void getEdgeTest(Function> graphImpl) { final Random rand = new Random(0xe2cdb0023327cb42L); foreachBoolConfig(directed -> { final int n = 100; - Graph g = graphImpl.get(directed); + Graph g = graphImpl.apply(directed); g.addVertices(range(1, n + 1)); List vs = new ArrayList<>(g.vertices()); @@ -1691,12 +1688,11 @@ static void getEdgeTest(Boolean2ObjectFunction> graphImp }); } - @SuppressWarnings("boxing") - static void testGetEdgesOutIn(Boolean2ObjectFunction> graphImpl) { + static void testGetEdgesOutIn(Function> graphImpl) { final Random rand = new Random(0x55785cf48eb6bf43L); foreachBoolConfig(directed -> { final int n = 100; - Graph g = graphImpl.get(directed); + Graph g = graphImpl.apply(directed); g.addVertices(range(1, n + 1)); List vs = new ArrayList<>(g.vertices()); @@ -1767,11 +1763,11 @@ static void testGetEdgesOutIn(Boolean2ObjectFunction> gr }); } - static void testGetEdgesSourceTarget(Boolean2ObjectFunction> graphImpl, long seed) { + static void testGetEdgesSourceTarget(Function> graphImpl, long seed) { Random rand = new Random(seed); foreachBoolConfig(directed -> { final int n = 100; - Graph g = graphImpl.get(directed); + Graph g = graphImpl.apply(directed); g.addVertices(range(1, n + 1)); List vs = new ArrayList<>(g.vertices()); @@ -1900,10 +1896,10 @@ static void testGetEdgesSourceTarget(Boolean2ObjectFunction> graphImpl) { + static void testEdgeIter(Function> graphImpl) { foreachBoolConfig(directed -> { final int n = 100; - Graph g = graphImpl.get(directed); + Graph g = graphImpl.apply(directed); g.addVertices(range(1, n + 1)); List vs = new ArrayList<>(g.vertices()); @@ -2010,13 +2006,12 @@ static void testEdgeIter(Boolean2ObjectFunction> graphIm }); } - @SuppressWarnings("boxing") - static void testEdgeIterRemoveSingle(Boolean2ObjectFunction> graphImpl) { + static void testEdgeIterRemoveSingle(Function> graphImpl) { final SeedGenerator seedGen = new SeedGenerator(0x95a73506247fe12L); final Random rand = new Random(seedGen.nextSeed()); foreachBoolConfig((directed, outIn) -> { - final boolean selfEdges = graphImpl.get(directed).isAllowSelfEdges(); - final boolean parallelEdges = graphImpl.get(directed).isAllowParallelEdges(); + final boolean selfEdges = graphImpl.apply(directed).isAllowSelfEdges(); + final boolean parallelEdges = graphImpl.apply(directed).isAllowParallelEdges(); for (int ops = 0; ops < 20; ops++) { Graph g = GraphsTestUtils .withImpl( @@ -2097,13 +2092,12 @@ static void testEdgeIterRemoveSingle(Boolean2ObjectFunction> graphImpl) { + static void testEdgeIterRemoveAll(Function> graphImpl) { final SeedGenerator seedGen = new SeedGenerator(0x95a73506247fe12L); final Random rand = new Random(seedGen.nextSeed()); foreachBoolConfig((directed, outIn) -> { - final boolean selfEdges = graphImpl.get(directed).isAllowSelfEdges(); - final boolean parallelEdges = graphImpl.get(directed).isAllowParallelEdges(); + final boolean selfEdges = graphImpl.apply(directed).isAllowSelfEdges(); + final boolean parallelEdges = graphImpl.apply(directed).isAllowParallelEdges(); for (int ops = 0; ops < 20; ops++) { Graph g = GraphsTestUtils .withImpl( @@ -2179,10 +2173,10 @@ static void testEdgeIterRemoveAll(Boolean2ObjectFunction }); } - static void testDegree(Boolean2ObjectFunction> graphImpl) { + static void testDegree(Function> graphImpl) { foreachBoolConfig(directed -> { final int n = 100; - Graph g = graphImpl.get(directed); + Graph g = graphImpl.apply(directed); g.addVertices(range(1, n + 1)); List vs = new ArrayList<>(g.vertices()); @@ -2210,10 +2204,10 @@ static void testDegree(Boolean2ObjectFunction> graphImpl }); } - static void testClear(Boolean2ObjectFunction> graphImpl, long seed) { + static void testClear(Function> graphImpl, long seed) { Random rand = new Random(seed); foreachBoolConfig(directed -> { - Graph g = graphImpl.get(directed); + Graph g = graphImpl.apply(directed); boolean parallelEdges = g.isAllowParallelEdges(); int totalOpNum = 1000; @@ -2258,10 +2252,10 @@ static void testClear(Boolean2ObjectFunction> graphImpl, }); } - static void testClearEdges(Boolean2ObjectFunction> graphImpl, long seed) { + static void testClearEdges(Function> graphImpl, long seed) { Random rand = new Random(seed); foreachBoolConfig(directed -> { - Graph g = graphImpl.get(directed); + Graph g = graphImpl.apply(directed); boolean parallelEdges = g.isAllowParallelEdges(); int totalOpNum = 1000; @@ -2312,7 +2306,7 @@ static void testClearEdges(Boolean2ObjectFunction> graph }); } - static void testCopy(Boolean2ObjectFunction> graphImpl, long seed) { + static void testCopy(Function> graphImpl, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); for (String copyType : List .of("origImpl", "array", "linked-list", "linked-list-ptr", "hashtable", "hashtable-multi", "matrix")) { @@ -2374,7 +2368,7 @@ static void testCopy(Boolean2ObjectFunction> graphImpl, } } - static void testCopyWithWeights(Boolean2ObjectFunction> graphImpl, long seed) { + static void testCopyWithWeights(Function> graphImpl, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); final Random rand = new Random(seedGen.nextSeed()); foreachBoolConfig(directed -> { @@ -2470,11 +2464,11 @@ static void testCopyWithWeights(Boolean2ObjectFunction> }); } - static void testImmutableCopy(Boolean2ObjectFunction> graphImpl, long seed) { + static void testImmutableCopy(Function> graphImpl, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); foreachBoolConfig(directed -> { /* Create a random graph g */ - boolean selfEdges = graphImpl.get(directed).isAllowSelfEdges(); + boolean selfEdges = graphImpl.apply(directed).isAllowSelfEdges(); Graph g = GraphsTestUtils .withImpl(GraphsTestUtils.randGraph(100, 300, directed, selfEdges, false, seedGen.nextSeed()), graphImpl); @@ -2522,12 +2516,12 @@ static void testImmutableCopy(Boolean2ObjectFunction> gr }); } - static void testImmutableCopyWithWeights(Boolean2ObjectFunction> graphImpl, long seed) { + static void testImmutableCopyWithWeights(Function> graphImpl, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); final Random rand = new Random(seedGen.nextSeed()); foreachBoolConfig(directed -> { /* Create a random graph g */ - boolean selfEdges = graphImpl.get(directed).isAllowSelfEdges(); + boolean selfEdges = graphImpl.apply(directed).isAllowSelfEdges(); Graph g = GraphsTestUtils .withImpl(GraphsTestUtils.randGraph(100, 300, directed, selfEdges, false, seedGen.nextSeed()), graphImpl); @@ -2740,14 +2734,13 @@ static void testBuilderConstructor(Function c }); } - @SuppressWarnings("boxing") - static void testRemoveEdge(Boolean2ObjectFunction> graphImpl) { + static void testRemoveEdge(Function> graphImpl) { final SeedGenerator seedGen = new SeedGenerator(0x95a73506247fe12L); final Random rand = new Random(seedGen.nextSeed()); foreachBoolConfig(directed -> { - final boolean selfEdges = graphImpl.get(directed).isAllowSelfEdges(); - final boolean parallelEdges = graphImpl.get(directed).isAllowParallelEdges(); + final boolean selfEdges = graphImpl.apply(directed).isAllowSelfEdges(); + final boolean parallelEdges = graphImpl.apply(directed).isAllowParallelEdges(); for (int ops = 0; ops < 20; ops++) { Graph g = GraphsTestUtils .withImpl( @@ -2813,12 +2806,12 @@ static void testRemoveEdge(Boolean2ObjectFunction> graph }); } - static void testReverseEdge(Boolean2ObjectFunction> graphImpl, long seed) { + static void testReverseEdge(Function> graphImpl, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); final Random rand = new Random(seedGen.nextSeed()); - final boolean selfEdges = graphImpl.get(true).isAllowSelfEdges(); - final boolean parallelEdges = graphImpl.get(true).isAllowParallelEdges(); + final boolean selfEdges = graphImpl.apply(true).isAllowSelfEdges(); + final boolean parallelEdges = graphImpl.apply(true).isAllowParallelEdges(); Graph g1 = GraphsTestUtils .withImpl(GraphsTestUtils.randGraph(100, 300, true, selfEdges, parallelEdges, seedGen.nextSeed()), graphImpl); @@ -2854,14 +2847,14 @@ static void testReverseEdge(Boolean2ObjectFunction> grap } } - static void testMoveEdge(Boolean2ObjectFunction> graphImpl) { + static void testMoveEdge(Function> graphImpl) { final long seed = 0x5aaa87a14dbb6a83L; final SeedGenerator seedGen = new SeedGenerator(seed); final Random rand = new Random(seedGen.nextSeed()); foreachBoolConfig(directed -> { - final boolean selfEdges = graphImpl.get(directed).isAllowSelfEdges(); - final boolean parallelEdges = graphImpl.get(directed).isAllowParallelEdges(); + final boolean selfEdges = graphImpl.apply(directed).isAllowSelfEdges(); + final boolean parallelEdges = graphImpl.apply(directed).isAllowParallelEdges(); Graph g1 = GraphsTestUtils .withImpl( GraphsTestUtils.randGraph(100, 300, directed, selfEdges, parallelEdges, seedGen.nextSeed()), @@ -2960,31 +2953,31 @@ static void testMoveEdge(Boolean2ObjectFunction> graphIm }); } - static void testUndirectedMST(Boolean2ObjectFunction> graphImpl, long seed) { + static void testUndirectedMST(Function> graphImpl, long seed) { MinimumSpanningTreeTestUtils.testRandGraph(MinimumSpanningTree.newInstance(), graphImpl, seed); } - static void testDirectedMDST(Boolean2ObjectFunction> graphImpl, long seed) { + static void testDirectedMDST(Function> graphImpl, long seed) { MinimumDirectedSpanningTreeTarjanTest.testRandGraph(MinimumDirectedSpanningTree.newInstance(), graphImpl, seed); } - static void testDirectedMaxFlow(Boolean2ObjectFunction> graphImpl, long seed) { + static void testDirectedMaxFlow(Function> graphImpl, long seed) { MaximumFlowTestUtils.testRandGraphs(MaximumFlow.newInstance(), graphImpl, seed, /* directed= */ true); } - static void testUndirectedBipartiteMatching(Boolean2ObjectFunction> graphImpl, long seed) { + static void testUndirectedBipartiteMatching(Function> graphImpl, long seed) { MatchingBipartiteTestUtils .randBipartiteGraphs(MatchingAlgo.builder().setBipartite(true).setCardinality(true).build(), graphImpl, seed); } - static void testUndirectedBipartiteMatchingWeighted(Boolean2ObjectFunction> graphImpl, + static void testUndirectedBipartiteMatchingWeighted(Function> graphImpl, long seed) { MatchingWeightedTestUtils .randGraphsBipartiteWeighted(MatchingAlgo.builder().setBipartite(true).build(), graphImpl, seed); } - static void testRandOps(Boolean2ObjectFunction> graphImpl, boolean directed, long seed) { + static void testRandOps(Function> graphImpl, boolean directed, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); PhasedTester tester = new PhasedTester(); tester.addPhase().withArgs(6, 6).repeat(2056); @@ -3000,10 +2993,10 @@ static void testRandOps(Boolean2ObjectFunction> graphImp }); } - private static void testRandOps(Boolean2ObjectFunction> graphImpl, boolean directed, int n, + private static void testRandOps(Function> graphImpl, boolean directed, int n, int m, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - boolean selfEdges = graphImpl.get(directed).isAllowSelfEdges(); + boolean selfEdges = graphImpl.apply(directed).isAllowSelfEdges(); Graph g = GraphsTestUtils .withImpl(GraphsTestUtils.randGraph(n, m, directed, selfEdges, false, seedGen.nextSeed()), graphImpl); final int opsNum = 128; diff --git a/jgalgo-core/src/test/java/com/jgalgo/graph/GraphLinkedPtrTest.java b/jgalgo-core/src/test/java/com/jgalgo/graph/GraphLinkedPtrTest.java index 34f71102ab..5e076181fa 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/graph/GraphLinkedPtrTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/graph/GraphLinkedPtrTest.java @@ -19,13 +19,13 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.Test; import com.jgalgo.internal.util.TestBase; -import it.unimi.dsi.fastutil.booleans.Boolean2ObjectFunction; +import java.util.function.Function; public class GraphLinkedPtrTest extends TestBase { - private static Boolean2ObjectFunction> graphImpl(boolean selfEdges) { + private static Function> graphImpl(boolean selfEdges) { return directed -> IntGraphFactory - .newInstance(directed) + .newInstance(directed.booleanValue()) .setOption("impl", selfEdges ? "linked-list-ptr-selfedges" : "linked-list-ptr") .newGraph(); } diff --git a/jgalgo-core/src/test/java/com/jgalgo/graph/GraphLinkedTest.java b/jgalgo-core/src/test/java/com/jgalgo/graph/GraphLinkedTest.java index 8eddb504d3..93eb1dbe36 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/graph/GraphLinkedTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/graph/GraphLinkedTest.java @@ -17,15 +17,15 @@ package com.jgalgo.graph; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.util.function.Function; import org.junit.jupiter.api.Test; import com.jgalgo.internal.util.TestBase; -import it.unimi.dsi.fastutil.booleans.Boolean2ObjectFunction; public class GraphLinkedTest extends TestBase { - private static Boolean2ObjectFunction> graphImpl(boolean selfEdges) { + private static Function> graphImpl(boolean selfEdges) { return directed -> IntGraphFactory - .newInstance(directed) + .newInstance(directed.booleanValue()) .setOption("impl", selfEdges ? "linked-list-selfedges" : "linked-list") .newGraph(); } diff --git a/jgalgo-core/src/test/java/com/jgalgo/graph/GraphMatrixTest.java b/jgalgo-core/src/test/java/com/jgalgo/graph/GraphMatrixTest.java index 38a1162b01..ae8c4c1013 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/graph/GraphMatrixTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/graph/GraphMatrixTest.java @@ -17,15 +17,15 @@ package com.jgalgo.graph; import static org.junit.jupiter.api.Assertions.assertFalse; +import java.util.function.Function; import org.junit.jupiter.api.Test; import com.jgalgo.internal.util.TestBase; -import it.unimi.dsi.fastutil.booleans.Boolean2ObjectFunction; public class GraphMatrixTest extends TestBase { - private static Boolean2ObjectFunction> graphImpl(boolean selfEdges) { + private static Function> graphImpl(boolean selfEdges) { return directed -> IntGraphFactory - .newInstance(directed) + .newInstance(directed.booleanValue()) .setOption("impl", selfEdges ? "matrix-selfedges" : "matrix") .newGraph(); } diff --git a/jgalgo-core/src/test/java/com/jgalgo/graph/GraphsTestUtils.java b/jgalgo-core/src/test/java/com/jgalgo/graph/GraphsTestUtils.java index 22634dc524..2bdd9ae55e 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/graph/GraphsTestUtils.java +++ b/jgalgo-core/src/test/java/com/jgalgo/graph/GraphsTestUtils.java @@ -18,6 +18,7 @@ import static com.jgalgo.internal.util.Range.range; import java.util.Random; +import java.util.function.Function; import com.jgalgo.gen.GnmBipartiteGraphGenerator; import com.jgalgo.gen.GnmGraphGenerator; import com.jgalgo.gen.UniformTreeGenerator; @@ -25,7 +26,6 @@ import com.jgalgo.internal.util.RandomIntUnique; import com.jgalgo.internal.util.TestUtils; import it.unimi.dsi.fastutil.Stack; -import it.unimi.dsi.fastutil.booleans.Boolean2ObjectFunction; import it.unimi.dsi.fastutil.ints.IntArrays; import it.unimi.dsi.fastutil.ints.IntIntPair; import it.unimi.dsi.fastutil.longs.LongOpenHashSet; @@ -214,7 +214,7 @@ public static Graph randForest(int n, int m, long seed) { @SuppressWarnings({ "unchecked", "boxing" }) public static Graph withImpl(Graph g, - Boolean2ObjectFunction> graphImpl) { + Function> graphImpl) { Graph g2 = graphImpl.apply(g.isDirected()); g2.addVertices(g.vertices()); g2.addEdges(EdgeSet.allOf(g)); @@ -254,11 +254,11 @@ private static Class getWeightsType(Weights w) { return Object.class; } - public static Boolean2ObjectFunction> defaultGraphImpl(long seed) { + public static Function> defaultGraphImpl(long seed) { if (new Random(seed).nextBoolean()) { - return directed -> IntGraphFactory.newInstance(directed).newGraph(); + return directed -> IntGraphFactory.newInstance(directed.booleanValue()).newGraph(); } else { - return directed -> GraphFactory.newInstance(directed).newGraph(); + return directed -> GraphFactory.newInstance(directed.booleanValue()).newGraph(); } } diff --git a/jgalgo-core/src/test/java/com/jgalgo/graph/IdBuilderTest.java b/jgalgo-core/src/test/java/com/jgalgo/graph/IdBuilderTest.java index 950f563968..ca1b41a002 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/graph/IdBuilderTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/graph/IdBuilderTest.java @@ -19,32 +19,30 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.ArrayList; +import java.util.HashSet; import java.util.Set; import org.junit.jupiter.api.Test; import com.jgalgo.internal.util.TestBase; -import it.unimi.dsi.fastutil.bytes.ByteOpenHashSet; import it.unimi.dsi.fastutil.doubles.DoubleOpenHashSet; -import it.unimi.dsi.fastutil.floats.FloatOpenHashSet; import it.unimi.dsi.fastutil.ints.IntList; import it.unimi.dsi.fastutil.ints.IntOpenHashSet; import it.unimi.dsi.fastutil.longs.LongList; import it.unimi.dsi.fastutil.longs.LongOpenHashSet; import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; -import it.unimi.dsi.fastutil.shorts.ShortOpenHashSet; public class IdBuilderTest extends TestBase { @Test public void defaultBuilderByte() { foreachBoolConfig(boxedType -> { - Set ids = new ByteOpenHashSet(); + Set ids = new HashSet<>(); IdBuilder builder = IdBuilder.defaultBuilder(boxedType ? Byte.class : byte.class); for (int i = 0; i < 100; i++) ids.add(builder.build(ids)); assertEquals(100, ids.size()); }); foreachBoolConfig(boxedType -> { - Set ids = new ByteOpenHashSet(); + Set ids = new HashSet<>(); IdBuilder builder = IdBuilder.defaultBuilder(boxedType ? Byte.class : byte.class); for (int i = 0; i < 256; i++) ids.add(builder.build(ids)); @@ -56,7 +54,7 @@ public void defaultBuilderByte() { @Test public void defaultBuilderShort() { foreachBoolConfig(boxedType -> { - Set ids = new ShortOpenHashSet(); + Set ids = new HashSet<>(); IdBuilder builder = IdBuilder.defaultBuilder(boxedType ? Short.class : short.class); for (int i = 0; i < 100; i++) ids.add(builder.build(ids)); @@ -103,7 +101,7 @@ public void defaultBuilderLong() { @Test public void defaultBuilderFloat() { foreachBoolConfig(boxedType -> { - Set ids = new FloatOpenHashSet(); + Set ids = new HashSet<>(); IdBuilder builder = IdBuilder.defaultBuilder(boxedType ? Float.class : float.class); for (int i = 0; i < 100; i++) ids.add(builder.build(ids)); diff --git a/jgalgo-core/src/test/java/com/jgalgo/graph/IndexGraphBuilderTest.java b/jgalgo-core/src/test/java/com/jgalgo/graph/IndexGraphBuilderTest.java index 7ac3586880..c2be076b0d 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/graph/IndexGraphBuilderTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/graph/IndexGraphBuilderTest.java @@ -34,7 +34,6 @@ import org.junit.jupiter.api.Test; import com.jgalgo.internal.util.TestBase; import it.unimi.dsi.fastutil.Pair; -import it.unimi.dsi.fastutil.booleans.BooleanList; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntArrays; import it.unimi.dsi.fastutil.ints.IntList; @@ -552,7 +551,7 @@ public void build() { AtomicInteger weightIdx = new AtomicInteger(); @SuppressWarnings("rawtypes") BiConsumer addWeights = (type, valSupplier) -> { - for (boolean edgesWeights : BooleanList.of(false, true)) { + foreachBoolConfig(edgesWeights -> { for (int repeat = 1 + rand.nextInt(2); repeat > 0; repeat--) { String key = "weight" + weightIdx.getAndIncrement(); Object defVal = valSupplier.get(); @@ -573,7 +572,7 @@ public void build() { wB.setAsObj(elm, w); } } - } + }); }; addWeights.accept(byte.class, () -> Byte.valueOf((byte) rand.nextInt())); addWeights.accept(short.class, () -> Short.valueOf((short) rand.nextInt())); diff --git a/jgalgo-core/src/test/java/com/jgalgo/graph/IntGraphBuilderTest.java b/jgalgo-core/src/test/java/com/jgalgo/graph/IntGraphBuilderTest.java index 44f27550c1..2b4b52350b 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/graph/IntGraphBuilderTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/graph/IntGraphBuilderTest.java @@ -36,7 +36,6 @@ import org.junit.jupiter.api.Test; import com.jgalgo.internal.util.TestBase; import it.unimi.dsi.fastutil.Pair; -import it.unimi.dsi.fastutil.booleans.BooleanList; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntList; import it.unimi.dsi.fastutil.ints.IntOpenHashSet; @@ -453,7 +452,7 @@ public void build() { AtomicInteger weightIdx = new AtomicInteger(); @SuppressWarnings("rawtypes") BiConsumer addWeights = (type, valSupplier) -> { - for (boolean edgesWeights : BooleanList.of(false, true)) { + foreachBoolConfig(edgesWeights -> { for (int repeat = 1 + rand.nextInt(2); repeat > 0; repeat--) { String key = "weight" + weightIdx.getAndIncrement(); Object defVal = valSupplier.get(); @@ -474,7 +473,7 @@ public void build() { wB.setAsObj(elm, w); } } - } + }); }; addWeights.accept(byte.class, () -> Byte.valueOf((byte) rand.nextInt())); addWeights.accept(short.class, () -> Short.valueOf((short) rand.nextInt())); diff --git a/jgalgo-core/src/test/java/com/jgalgo/graph/IntGraphImplTest.java b/jgalgo-core/src/test/java/com/jgalgo/graph/IntGraphImplTest.java index 6f12f59ee5..a12a21aec8 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/graph/IntGraphImplTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/graph/IntGraphImplTest.java @@ -243,8 +243,10 @@ public void addEdgeWithEdgeBuilder() { public void addEdges() { foreachBoolConfig(selfEdges -> { GraphImplTestUtils - .addEdgesTest( - directed -> IntGraphFactory.newInstance(directed).allowSelfEdges(selfEdges).newGraph()); + .addEdgesTest(directed -> IntGraphFactory + .newInstance(directed.booleanValue()) + .allowSelfEdges(selfEdges) + .newGraph()); }); } diff --git a/jgalgo-core/src/test/java/com/jgalgo/internal/ds/RedBlackTreeExtendedTest.java b/jgalgo-core/src/test/java/com/jgalgo/internal/ds/RedBlackTreeExtendedTest.java index 8f64fee3da..ff9743ec0b 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/internal/ds/RedBlackTreeExtendedTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/internal/ds/RedBlackTreeExtendedTest.java @@ -17,6 +17,7 @@ package com.jgalgo.internal.ds; import static org.junit.jupiter.api.Assertions.assertEquals; +import java.util.IdentityHashMap; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -25,7 +26,6 @@ import com.jgalgo.internal.util.TestBase; import it.unimi.dsi.fastutil.ints.IntComparator; import it.unimi.dsi.fastutil.objects.ObjectIterables; -import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap; @SuppressWarnings("boxing") public class RedBlackTreeExtendedTest extends TestBase { @@ -122,9 +122,9 @@ private static IntReferenceableHeap intRefHeapFromObjObjRefHeap(ObjObjReferencea return new IntReferenceableHeap() { final Map> refIntToObj = - new Reference2ObjectOpenHashMap<>(); + new IdentityHashMap<>(); final Map, IntReferenceableHeap.Ref> refObjToRef = - new Reference2ObjectOpenHashMap<>(); + new IdentityHashMap<>(); @Override public void clear() { diff --git a/jgalgo-core/src/test/java/com/jgalgo/internal/util/TestUtils.java b/jgalgo-core/src/test/java/com/jgalgo/internal/util/TestUtils.java index 37a219819b..c5914b2d04 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/internal/util/TestUtils.java +++ b/jgalgo-core/src/test/java/com/jgalgo/internal/util/TestUtils.java @@ -24,7 +24,6 @@ import java.util.function.Consumer; import org.junit.jupiter.api.Assertions; import com.jgalgo.graph.Graph; -import it.unimi.dsi.fastutil.booleans.BooleanList; import it.unimi.dsi.fastutil.ints.IntArrays; import it.unimi.dsi.fastutil.ints.IntList; @@ -189,28 +188,28 @@ public static void assertNotEqualsBool(boolean unexpected, boolean actual) { } public static void foreachBoolConfig(RunnableWith1BoolConfig test) { - for (boolean cfg1 : BooleanList.of(false, true)) + for (boolean cfg1 : new boolean[] { false, true }) test.run(cfg1); } public static void foreachBoolConfig(RunnableWith2BoolConfig test) { - for (boolean cfg1 : BooleanList.of(false, true)) - for (boolean cfg2 : BooleanList.of(false, true)) + for (boolean cfg1 : new boolean[] { false, true }) + for (boolean cfg2 : new boolean[] { false, true }) test.run(cfg1, cfg2); } public static void foreachBoolConfig(RunnableWith3BoolConfig test) { - for (boolean cfg1 : BooleanList.of(false, true)) - for (boolean cfg2 : BooleanList.of(false, true)) - for (boolean cfg3 : BooleanList.of(false, true)) + for (boolean cfg1 : new boolean[] { false, true }) + for (boolean cfg2 : new boolean[] { false, true }) + for (boolean cfg3 : new boolean[] { false, true }) test.run(cfg1, cfg2, cfg3); } public static void foreachBoolConfig(RunnableWith4BoolConfig test) { - for (boolean cfg1 : BooleanList.of(false, true)) - for (boolean cfg2 : BooleanList.of(false, true)) - for (boolean cfg3 : BooleanList.of(false, true)) - for (boolean cfg4 : BooleanList.of(false, true)) + for (boolean cfg1 : new boolean[] { false, true }) + for (boolean cfg2 : new boolean[] { false, true }) + for (boolean cfg3 : new boolean[] { false, true }) + for (boolean cfg4 : new boolean[] { false, true }) test.run(cfg1, cfg2, cfg3, cfg4); } diff --git a/jgalgo-io/pom.xml b/jgalgo-io/pom.xml index 1a3e5fd9a1..8fcab9a960 100644 --- a/jgalgo-io/pom.xml +++ b/jgalgo-io/pom.xml @@ -17,6 +17,12 @@ ${project.groupId} jgalgo-core ${project.version} + + + it.unimi.dsi + fastutil + +