class HashTreeUtil {

  static void merge(Bytes32 h, int i, List<Bytes32> tmp, long count, int depth) {
    int j = 0;
    while (true) {
      if ((i & (1 << j)) == 0) {
        if (i == count && j < depth) {
          h = Hash.sha2_256(Bytes.concatenate(h, zerohashes.get(j)));
        } else {
          break;
        }
      } else {
        h = Hash.sha2_256(Bytes.concatenate(tmp.get(j), h));
      }
      j += 1;
    }
    tmp.set(j, h);
  }

}