/** * Return the total count of points that have been added to the tree. */ public int sum() { return aggregatedCounts[tree.root()]; }
/** * Return the least node in the tree. */ @SuppressWarnings("WeakerAccess") public int last() { return tree.last(tree.root()); }
/** * Return the least node in the tree. */ public int first() { return tree.first(tree.root()); }
void checkAggregates() { checkAggregates(tree.root()); }
void checkBalance() { tree.checkBalance(tree.root()); }
/** * Return the last node whose centroid is less than <code>centroid</code>. */ @SuppressWarnings("WeakerAccess") public int floor(double centroid) { int floor = IntAVLTree.NIL; for (int node = tree.root(); node != IntAVLTree.NIL; ) { final int cmp = Double.compare(centroid, mean(node)); if (cmp <= 0) { node = tree.left(node); } else { floor = node; node = tree.right(node); } } return floor; }
/** * Return the last node so that the sum of counts of nodes that are before * it is less than or equal to <code>sum</code>. */ @SuppressWarnings("WeakerAccess") public int floorSum(long sum) { int floor = IntAVLTree.NIL; for (int node = tree.root(); node != IntAVLTree.NIL; ) { final int left = tree.left(node); final long leftCount = aggregatedCounts[left]; if (leftCount <= sum) { floor = node; sum -= leftCount + count(node); node = tree.right(node); } else { node = tree.left(node); } } return floor; }
/** * Return the total count of points that have been added to the tree. */ public int sum() { return aggregatedCounts[tree.root()]; }
/** * Return the least node in the tree. */ public int first() { return tree.first(tree.root()); }
void checkBalance() { tree.checkBalance(tree.root()); }
void checkAggregates() { checkAggregates(tree.root()); }
/** * Return the last node whose centroid is less than <code>centroid</code>. */ public int floor(double centroid) { int floor = IntAVLTree.NIL; for (int node = tree.root(); node != IntAVLTree.NIL; ) { final int cmp = Double.compare(centroid, mean(node)); if (cmp <= 0) { node = tree.left(node); } else { floor = node; node = tree.right(node); } } return floor; }
/** * Return the last node so that the sum of counts of nodes that are before * it is less than or equal to <code>sum</code>. */ public int floorSum(long sum) { int floor = IntAVLTree.NIL; for (int node = tree.root(); node != IntAVLTree.NIL; ) { final int left = tree.left(node); final long leftCount = aggregatedCounts[left]; if (leftCount <= sum) { floor = node; sum -= leftCount + count(node); node = tree.right(node); } else { node = tree.left(node); } } return floor; }