Skip to content

Commit

Permalink
Remove TreePathMaxima.Builder
Browse files Browse the repository at this point in the history
  • Loading branch information
barakugav committed Jun 28, 2024
1 parent 304e98f commit 05fd7ed
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.infra.Blackhole;
import com.jgalgo.alg.tree.TreePathMaxima;
import com.jgalgo.alg.tree.TreePathMaximaHagerup;
import com.jgalgo.bench.util.BenchUtils;
import com.jgalgo.bench.util.GraphsTestUtils;
import com.jgalgo.bench.util.TestUtils.SeedGenerator;
Expand Down Expand Up @@ -85,16 +86,16 @@ private void benchTPM(TreePathMaxima algo, Blackhole blackhole) {

@Benchmark
public void TPMHagerup(Blackhole blackhole) {
TreePathMaxima.Builder builder = TreePathMaxima.builder();
builder.setOption("bits-lookup-tables-enable", Boolean.FALSE);
benchTPM(builder.build(), blackhole);
TreePathMaximaHagerup algo = new TreePathMaximaHagerup();
algo.setBitsLookupTablesEnable(false);
benchTPM(algo, blackhole);
}

@Benchmark
public void TPMHagerupWithBitsLookupTable(Blackhole blackhole) {
TreePathMaxima.Builder builder = TreePathMaxima.builder();
builder.setOption("bits-lookup-tables-enable", Boolean.TRUE);
benchTPM(builder.build(), blackhole);
TreePathMaximaHagerup algo = new TreePathMaximaHagerup();
algo.setBitsLookupTablesEnable(true);
benchTPM(algo, blackhole);
}

private static class TPMArgs {
Expand Down
59 changes: 3 additions & 56 deletions jgalgo-core/src/main/java/com/jgalgo/alg/tree/TreePathMaxima.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import static com.jgalgo.internal.util.Range.range;
import java.util.Collection;
import java.util.Objects;
import com.jgalgo.alg.AlgorithmBuilderBase;
import com.jgalgo.graph.Graph;
import com.jgalgo.graph.IWeightFunction;
import com.jgalgo.graph.IndexGraph;
Expand Down Expand Up @@ -48,8 +47,7 @@
* linear time.
*
* <p>
* 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.
*
* @author Barak Ugav
*/
Expand Down Expand Up @@ -319,63 +317,12 @@ default Integer getHeaviestEdge(int queryIdx) {
* Create a new tree path maxima algorithm object.
*
* <p>
* This is the recommended way to instantiate a new {@link TreePathMaxima} object. The
* {@link TreePathMaxima.Builder} might support different options to obtain different implementations.
* This is the recommended way to instantiate a new {@link TreePathMaxima} object.
*
* @return a default implementation of {@link TreePathMaxima}
*/
static TreePathMaxima newInstance() {
return builder().build();
}

/**
* Create a new tree path maxima algorithm builder.
*
* <p>
* Use {@link #newInstance()} for a default implementation.
*
* @return a new builder that can build {@link TreePathMaxima} objects
*/
static TreePathMaxima.Builder builder() {
return new TreePathMaxima.Builder() {

boolean bitsLookupTablesEnable;

@Override
public TreePathMaxima build() {
TreePathMaximaHagerup tpm = new TreePathMaximaHagerup();
tpm.setBitsLookupTablesEnable(bitsLookupTablesEnable);
return tpm;
}

@Override
public void setOption(String key, Object value) {
switch (key) {
case "bits-lookup-tables-enable":
bitsLookupTablesEnable = ((Boolean) value).booleanValue();
break;
default:
TreePathMaxima.Builder.super.setOption(key, value);
}
}

};
}

/**
* A builder for {@link TreePathMaxima} objects.
*
* @see TreePathMaxima#builder()
* @author Barak Ugav
*/
static interface Builder extends AlgorithmBuilderBase {

/**
* Create a new algorithm object for tree path maxima computation.
*
* @return a new tree path maxima algorithm
*/
TreePathMaxima build();
return new TreePathMaximaHagerup();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,10 @@ public TreePathMaximaHagerup() {}
* <p>
* This method enable or disable the use of bits lookup tables.
*
* @see BitsLookupTable
* @param enable if {@code true} bits lookup table will be constructed and used, else methods from {@link Integer}
* will be used.
*/
void setBitsLookupTablesEnable(boolean enable) {
public void setBitsLookupTablesEnable(boolean enable) {
useBitsLookupTables = enable;
}

Expand Down

0 comments on commit 05fd7ed

Please sign in to comment.