code: @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;
      }
docs: Compute the number of elements and sum of counts for every entry that
  is strictly before <code>node</code>.