Skip to content

Commit 7eb40ae

Browse files
committed
Address PR feedback
1 parent ce97578 commit 7eb40ae

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/logic/bdd/BddBuilder.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ final class BddBuilder {
3030
private static final int FALSE_REF = -1;
3131

3232
// Node storage: three separate arrays
33-
private int[] variables = new int[1024];
34-
private int[] highs = new int[1024];
35-
private int[] lows = new int[1024];
33+
private static final int INITIAL_SIZE = 256;
34+
private int[] variables = new int[INITIAL_SIZE];
35+
private int[] highs = new int[INITIAL_SIZE];
36+
private int[] lows = new int[INITIAL_SIZE];
3637
private int nodeCount;
3738

3839
// Unique tables for node deduplication and ITE caching
@@ -48,7 +49,7 @@ final class BddBuilder {
4849
public BddBuilder() {
4950
this.nodeCount = 1;
5051
this.uniqueTable = new UniqueTable();
51-
this.iteCache = new UniqueTable(4096); // Larger initial capacity for ITE cache
52+
this.iteCache = new UniqueTable(1024);
5253
initializeTerminalNode();
5354
}
5455

smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/logic/bdd/BddCompiler.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,9 @@ private int convertCfgToBdd(CfgNode cfgNode) {
9090
int result;
9191
if (cfgNode == null) {
9292
result = bddBuilder.makeResult(noMatchIndex);
93-
9493
} else if (cfgNode instanceof ResultNode) {
9594
Rule rule = ((ResultNode) cfgNode).getResult();
9695
result = bddBuilder.makeResult(getOrCreateResultIndex(rule));
97-
9896
} else {
9997
ConditionNode cn = (ConditionNode) cfgNode;
10098
ConditionReference ref = cn.getCondition();

smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/logic/bdd/BddEquivalenceChecker.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*
2828
* <p>This verifier uses structural equivalence checking to ensure that both representations produce the same result.
2929
* When the BDD has fewer than 20 conditions, the checking is exhaustive. When there are more, random samples are
30-
* checked up the earlier of max samples being reached, or the max duration being reached.
30+
* checked up the earlier of max samples being reached or the max duration being reached.
3131
*/
3232
public final class BddEquivalenceChecker {
3333

@@ -210,11 +210,12 @@ private void verifyCriticalCases() {
210210
verifyCase(allTrue ^ (1L << i));
211211
}
212212

213-
// Alternating patterns
213+
// Alternating patterns: 0101... (even conditions false, odd true)
214214
if (!hasEitherLimitBeenExceeded()) {
215215
verifyCase(0x5555555555555555L & ((1L << bdd.getConditionCount()) - 1));
216216
}
217217

218+
// Pattern: 1010... (even conditions true, odd false)
218219
if (!hasEitherLimitBeenExceeded()) {
219220
verifyCase(0xAAAAAAAAAAAAAAAAL & ((1L << bdd.getConditionCount()) - 1));
220221
}

smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/logic/bdd/BddTrait.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.List;
1616
import java.util.Set;
1717
import java.util.function.Function;
18+
import software.amazon.smithy.model.node.ArrayNode;
1819
import software.amazon.smithy.model.node.Node;
1920
import software.amazon.smithy.model.node.ObjectNode;
2021
import software.amazon.smithy.model.shapes.ShapeId;
@@ -130,14 +131,14 @@ protected Node createNode() {
130131
ObjectNode.Builder builder = ObjectNode.builder();
131132
builder.withMember("parameters", parameters.toNode());
132133

133-
List<Node> conditionNodes = new ArrayList<>();
134+
ArrayNode.Builder conditionBuilder = ArrayNode.builder();
134135
for (Condition c : conditions) {
135-
conditionNodes.add(c.toNode());
136+
conditionBuilder.withValue(c);
136137
}
137-
builder.withMember("conditions", Node.fromNodes(conditionNodes));
138+
builder.withMember("conditions", conditionBuilder.build());
138139

139140
// Results (skip NoMatchRule at index 0 for serialization)
140-
List<Node> resultNodes = new ArrayList<>();
141+
ArrayNode.Builder resultBuilder = ArrayNode.builder();
141142
if (!results.isEmpty() && !(results.get(0) instanceof NoMatchRule)) {
142143
throw new IllegalStateException("BDD must always have a NoMatchRule as the first result");
143144
}
@@ -146,9 +147,9 @@ protected Node createNode() {
146147
if (result instanceof NoMatchRule) {
147148
throw new IllegalStateException("NoMatch rules can only appear at rule index 0. Found at index " + i);
148149
}
149-
resultNodes.add(result.toNode());
150+
resultBuilder.withValue(result);
150151
}
151-
builder.withMember("results", Node.fromNodes(resultNodes));
152+
builder.withMember("results", resultBuilder.build());
152153

153154
builder.withMember("root", bdd.getRootRef());
154155
builder.withMember("nodeCount", bdd.getNodeCount());

0 commit comments

Comments
 (0)