Skip to content

Commit

Permalink
Branches dertect when they can devolve into an already built node.
Browse files Browse the repository at this point in the history
  • Loading branch information
brianburton committed Feb 24, 2024
1 parent 9bb8e38 commit e4c69e2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -370,11 +370,15 @@ private Node<T> toNode(Node<T> suffix)
assert suffix.size() < capacity;

if (size > 0) {
suffix = BranchNode.forNodeBuilder(depth,
size + suffix.size(),
prefix,
IndexedArray.retained(nodes), 0, length,
suffix);
if (prefix.isEmpty() && suffix.isEmpty() && length == 1) {
suffix = nodes[0];
} else {
suffix = BranchNode.forNodeBuilder(depth,
size + suffix.size(),
prefix,
IndexedArray.retained(nodes), 0, length,
suffix);
}
}
if (next == null) {
return suffix;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,15 @@ private Node<T> toNode(Node<T> prefix)
assert prefix.size() < capacity;

if (size > 0) {
prefix = BranchNode.forNodeBuilder(depth,
size + prefix.size(),
prefix,
IndexedArray.retained(nodes), index, 32,
suffix);
if (prefix.isEmpty() && suffix.isEmpty() && length == 1) {
prefix = nodes[index];
} else {
prefix = BranchNode.forNodeBuilder(depth,
size + prefix.size(),
prefix,
IndexedArray.retained(nodes), index, 32,
suffix);
}
}
if (next == null) {
return prefix;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public static void main(String[] argv)
final OptionSpec<String> fileSpec = parser.accepts("file", "specifies tokens file").withOptionalArg().ofType(String.class).defaultsTo("src/site/markdown/index.md");
final OptionSpec<Long> seedSpec = parser.accepts("seed", "specifies random number seed").withOptionalArg().ofType(Long.class).defaultsTo(System.currentTimeMillis());
final OptionSpec<String> testSpec = parser.accepts("test", "specifies tests to run").withRequiredArg().ofType(String.class);
final OptionSpec<Integer> loopsSpec = parser.accepts("loops", "specifies max number of loops to run").withOptionalArg().ofType(Integer.class).defaultsTo(-1);
final OptionSet options;
try {
options = parser.parse(argv);
Expand All @@ -137,18 +138,19 @@ public static void main(String[] argv)

long seed = options.valueOf(seedSpec);
final Random random = new Random(seed);
final int maxLoops = options.valueOf(loopsSpec);
int loopNumber = 1;

System.out.printf("%nRunning %d testers: %s%n", selectedTests.size(), valuesString(selectedTests.transform(StressTester::getTestName)));
//noinspection InfiniteLoopStatement
while (true) {
while (maxLoops < 0 || loopNumber <= maxLoops) {
for (StressTester tester : selectedTests) {
System.out.printf("%nStarting %s with seed %d%n", tester.getTestName(), seed);
System.out.printf("%nLoop %d Starting %s with seed %d%n", loopNumber, tester.getTestName(), seed);
tester.execute(random, tokens);
seed = System.currentTimeMillis();
random.setSeed(seed);
System.out.println("sleeping before next test");
//noinspection BusyWait
Thread.sleep(5000);
Thread.sleep(2000);
loopNumber += 1;
}
}
}
Expand Down

0 comments on commit e4c69e2

Please sign in to comment.