code: public static long calculateIndex(List<AggregationChainLink> links) {
          notNull(links, "Aggregation chain links");
          long chainIndex = 0;
          for (int i = 0; i < links.size(); i++) {
              if (links.get(i).isLeft()) {
                  chainIndex |= 1L << i;
              }
          }
          chainIndex |= 1L << links.size();
          return chainIndex;
      }
docs: Calculates chain index
  
  @param links Chain links for which to calculate the index
  @return Index of the chain