Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/query-stats-followup' in…
Browse files Browse the repository at this point in the history
…to staging/query-statistics
  • Loading branch information
awildturtok committed Jan 3, 2024
2 parents 84f9d28 + 9f36dbb commit 2c1b53a
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,32 @@ private List<Node> mergeLeft(Node[] nodes) {
}

private List<Node> splitRight(List<Node> nodes) {
final int expectedBinSize = total / expectedBins;

final List<Node> bins = new ArrayList<>();

final Deque<Node> frontier = new ArrayDeque<>(nodes);

while(!frontier.isEmpty()) {
final Node node = frontier.pop();
if (node.getCount() <= (total / expectedBins * 1.5d)) {
if (node.getCount() <= (expectedBinSize * 1.5d)) {
bins.add(node);
continue;
}

frontier.addFirst(node.split().get(1));
frontier.addFirst(node.split().get(0));
final List<Node> split = node.split();

final Node lower = split.get(0);
final Node higher = split.get(1);

// node has a heavy bias
if(Math.min(higher.getCount(), lower.getCount()) <= expectedBinSize * 0.1d){
bins.add(node);
continue;
}

frontier.addFirst(higher);
frontier.addFirst(lower);
}

return bins;
Expand Down

0 comments on commit 2c1b53a

Please sign in to comment.