Skip to content

Commit

Permalink
Fix nondeterministic descent again
Browse files Browse the repository at this point in the history
  • Loading branch information
jg-rp committed Mar 16, 2024
1 parent ec50ecb commit 7191632
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/path/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,15 +476,16 @@ export class RecursiveDescentSegment extends JSONPathSelector {
while (queue.length) {
const node = queue.shift() as JSONPathNode;
rv.push(node);
// Visit child nodes now or queue them for later?
const visit_children = Math.random() < 0.5;
for (const child of children(node)) {
// Queue the child node or visit now?
if (Math.random() < 0.5) {
queue.push(child);
} else {
if (visit_children) {
rv.push(child);
for (const _child of children(child)) {
queue.push(_child);
}
} else {
queue.push(child);
}
}
}
Expand Down

0 comments on commit 7191632

Please sign in to comment.