BDDPacket: don't create picker until it's used
@@ -5,6 +5,7 @@ import static org.batfish.common.bdd.BDDInteger.makeFromIndex;
import static org.batfish.common.bdd.BDDUtils.isAssignment;
import static org.batfish.common.bdd.BDDUtils.swapPairing;
+import com.google.common.base.Suppliers;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -12,6 +13,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
+import java.util.function.Supplier;
import net.sf.javabdd.BDD;
import net.sf.javabdd.BDDFactory;
import net.sf.javabdd.BDDPairing;
@@ -119,7 +121,12 @@ public class BDDPacket {
private final BDDPairing _swapSourceAndDestinationPairing;
// Picking representative flows
- private final BDDRepresentativePicker _picker;
+ private final Supplier<BDDRepresentativePicker> _picker =
+ Suppliers.memoize(
+ () ->
+ new BDDRepresentativePicker(
+ new BDDFlowConstraintGenerator(this)
+ .generateFlowPreference(FlowPreference.DEBUGGING)));
/*
* Creates a collection of BDD variables representing the
@@ -187,10 +194,6 @@ public class BDDPacket {
swapPairing(
getDstIp(), getSrcIp(), //
getDstPort(), getSrcPort());
-
- _picker =
- new BDDRepresentativePicker(
- new BDDFlowConstraintGenerator(this).generateFlowPreference(FlowPreference.DEBUGGING));
}
/*
@@ -302,7 +305,7 @@ public class BDDPacket {
* @return A Flow.Builder for a representative of the set, if it's non-empty
*/
public Optional<Flow.Builder> getFlow(BDD bdd) {
- BDD representativeBDD = _picker.pickRepresentative(bdd);
+ BDD representativeBDD = _picker.get().pickRepresentative(bdd);
if (representativeBDD.isZero()) {
return Optional.empty();
}
