From 72ca3e37a72ffa662696ba0a58a93c91027d0e40 Mon Sep 17 00:00:00 2001 From: Barak Ugav Date: Fri, 28 Jun 2024 09:05:14 +0300 Subject: [PATCH] Remove ShortestPathSt.Builder --- .../bench/impls/ShortestPathStBench.java | 7 ++- .../com/jgalgo/alg/path/ShortestPathSt.java | 59 ++++--------------- 2 files changed, 17 insertions(+), 49 deletions(-) diff --git a/jgalgo-bench/src/main/java/com/jgalgo/bench/impls/ShortestPathStBench.java b/jgalgo-bench/src/main/java/com/jgalgo/bench/impls/ShortestPathStBench.java index 1bfc233531..1f7c46264a 100644 --- a/jgalgo-bench/src/main/java/com/jgalgo/bench/impls/ShortestPathStBench.java +++ b/jgalgo-bench/src/main/java/com/jgalgo/bench/impls/ShortestPathStBench.java @@ -39,6 +39,7 @@ import com.jgalgo.alg.path.ShortestPathHeuristicSt; import com.jgalgo.alg.path.ShortestPathSingleSource; import com.jgalgo.alg.path.ShortestPathSt; +import com.jgalgo.alg.path.ShortestPathStBidirectionalDijkstra; import com.jgalgo.bench.util.BenchUtils; import com.jgalgo.bench.util.GraphsTestUtils; import com.jgalgo.bench.util.TestUtils.SeedGenerator; @@ -109,7 +110,7 @@ public void setup() { @Benchmark public void BidirectionalDijkstra(Blackhole blackhole) { - benchStShortestPath(ShortestPathSt.builder().build(), blackhole); + benchStShortestPath(new ShortestPathStBidirectionalDijkstra(), blackhole); } @Benchmark @@ -151,7 +152,7 @@ public void setup() { @Benchmark public void BidirectionalDijkstra(Blackhole blackhole) { - benchStShortestPath(ShortestPathSt.builder().build(), blackhole); + benchStShortestPath(new ShortestPathStBidirectionalDijkstra(), blackhole); } @Benchmark @@ -194,7 +195,7 @@ public void setup() { @Benchmark public void BidirectionalDijkstra(Blackhole blackhole) { - benchStShortestPath(ShortestPathSt.builder().build(), blackhole); + benchStShortestPath(new ShortestPathStBidirectionalDijkstra(), blackhole); } @Benchmark diff --git a/jgalgo-core/src/main/java/com/jgalgo/alg/path/ShortestPathSt.java b/jgalgo-core/src/main/java/com/jgalgo/alg/path/ShortestPathSt.java index f78271c9a8..6914b87755 100644 --- a/jgalgo-core/src/main/java/com/jgalgo/alg/path/ShortestPathSt.java +++ b/jgalgo-core/src/main/java/com/jgalgo/alg/path/ShortestPathSt.java @@ -15,7 +15,6 @@ */ package com.jgalgo.alg.path; -import com.jgalgo.alg.AlgorithmBuilderBase; import com.jgalgo.graph.Graph; import com.jgalgo.graph.IWeightFunction; import com.jgalgo.graph.IntGraph; @@ -36,8 +35,7 @@ * A variant with a heuristic distance function is also available, see {@link ShortestPathHeuristicSt}. * *

- * Use {@link #newInstance()} to get a default implementation of this interface. A builder obtained via - * {@link #builder()} may support different options to obtain different implementations. + * Use {@link #newInstance()} to get a default implementation of this interface. * * @see ShortestPathSingleSource * @see ShortestPathAllPairs @@ -89,56 +87,25 @@ ObjectDoublePair> computeShortestPathAndWeight(Graph g, * Create a new S-T shortest path algorithm object. * *

- * This is the recommended way to instantiate a new {@link ShortestPathSt} object. The - * {@link ShortestPathSt.Builder} might support different options to obtain different implementations. + * This is the recommended way to instantiate a new {@link ShortestPathSt} object. * * @return a default implementation of {@link ShortestPathSt} */ static ShortestPathSt newInstance() { - return builder().build(); - } - - /** - * Create a new S-T shortest path algorithm builder. - * - *

- * Use {@link #newInstance()} for a default implementation. - * - * @return a new builder that can build {@link ShortestPathSt} objects - */ - static ShortestPathSt.Builder builder() { - return () -> { - return new ShortestPathSt() { - ShortestPathSt cardinalityStSp = new ShortestPathStBidirectionalBfs(); - ShortestPathSt weightedStSp = new ShortestPathStBidirectionalDijkstra(); + return new ShortestPathSt() { + ShortestPathSt cardinalityStSp = new ShortestPathStBidirectionalBfs(); + ShortestPathSt weightedStSp = new ShortestPathStBidirectionalDijkstra(); - @Override - public ObjectDoublePair> computeShortestPathAndWeight(Graph g, - WeightFunction w, V source, V target) { - if (WeightFunction.isCardinality(w)) { - return cardinalityStSp.computeShortestPathAndWeight(g, null, source, target); - } else { - return weightedStSp.computeShortestPathAndWeight(g, w, source, target); - } + @Override + public ObjectDoublePair> computeShortestPathAndWeight(Graph g, WeightFunction w, + V source, V target) { + if (WeightFunction.isCardinality(w)) { + return cardinalityStSp.computeShortestPathAndWeight(g, null, source, target); + } else { + return weightedStSp.computeShortestPathAndWeight(g, w, source, target); } - }; + } }; } - /** - * A builder for {@link ShortestPathSt} objects. - * - * @see ShortestPathSt#builder() - * @author Barak Ugav - */ - static interface Builder extends AlgorithmBuilderBase { - - /** - * Create a new algorithm object for S-T shortest path computation. - * - * @return a new S-T shortest path algorithm - */ - ShortestPathSt build(); - } - }