AVLGroupTree extends AbstractCollection<Centroid> implements Serializable { @SuppressWarnings("WeakerAccess") public long headSum(int node) { final int left = tree.left(node); long sum = aggregatedCounts[left]; for (int n = node, p = tree.parent(node); p != IntAVLTree.NIL; n = p, p = tree.parent(n)) { if (n == tree.right(p)) { final int leftP = tree.left(p); sum += counts[p] + aggregatedCounts[leftP]; } } return sum; } AVLGroupTree();   AVLGroupTree(final boolean record); int size(); int prev(int node); int next(int node); double mean(int node); int count(int node); List<Double> data(int node); void add(double centroid, int count, List<Double> data); @Override boolean add(Centroid centroid); @SuppressWarnings("WeakerAccess") void update(int node, double centroid, int count, List<Double> data, boolean forceInPlace); void remove(int node); @SuppressWarnings("WeakerAccess") int floor(double centroid); @SuppressWarnings("WeakerAccess") int floorSum(long sum); int first(); @SuppressWarnings("WeakerAccess") int last(); @SuppressWarnings("WeakerAccess") long headSum(int node); @Override Iterator<Centroid> iterator(); int sum();  }
@Test public void testHeadSum() { AVLGroupTree x = new AVLGroupTree(false); for (int i = 0; i < 1000; ++i) { x.add(randomDouble(), randomIntBetween(1, 10), null); } long sum = 0; long last = -1; for (int node = x.first(); node != IntAVLTree.NIL; node = x.next(node)) { assertEquals(sum, x.headSum(node)); sum += x.count(node); last = x.count(node); } assertEquals(last, x.count(x.last())); }