@Override
  public UnionWeight<W> plus(UnionWeight<W> a, UnionWeight<W> b) {
    if (isZero(a)) return b;
    if (isZero(b)) return a;

    ImmutableList.Builder<W> builder = ImmutableList.builder();
    int cursorA = 0;
    int cursorB = 0;

    while (cursorA < a.size() && cursorB < b.size()) {
      W nextA = a.get(cursorA);
      W nextB = b.get(cursorB);

      int compare = ordering.compare(nextA, nextB);
      if (compare < 0) {
        builder.add(nextA);
        cursorA += 1;
      } else if (compare > 0) {
        builder.add(nextB);
        cursorB += 1;
      } else {
        // compare == 0, they are equal, then merge; because a and b are legal UnionWeights already we know they
        // don't have any duplicates so we can increment both
        builder.add(mergeStrategy.merge(nextA, nextB));
        cursorA += 1;
        cursorB += 1;
      }
    }
    for (; cursorA < a.size(); cursorA++) {
      builder.add(a.get(cursorA));
    }
    for (; cursorB < b.size(); cursorB++) {
      builder.add(b.get(cursorB));
    }
    return makeCheckedFrom(builder.build());
  }
@ Override public UnionWeight < W > plus ( UnionWeight < W > a , UnionWeight < W > b ) { if ( isZero ( a ) ) return b ; if ( isZero ( b ) ) return a ; ImmutableList . Builder < W > builder = ImmutableList . builder ( ) ; int cursorA = 0 ; int cursorB = 0 ; while ( cursorA < a . size ( ) && cursorB < b . size ( ) ) { W nextA = a . get ( cursorA ) ; W nextB = b . get ( cursorB ) ; int compare = ordering . compare ( nextA , nextB ) ; if ( compare < 0 ) { builder . add ( nextA ) ; cursorA += 1 ; } else if ( compare > 0 ) { builder . add ( nextB ) ; cursorB += 1 ; } else { builder . add ( mergeStrategy . merge ( nextA , nextB ) ) ; cursorA += 1 ; cursorB += 1 ; } } for ( ; cursorA < a . size ( ) ; cursorA ++ ) { builder . add ( a . get ( cursorA ) ) ; } for ( ; cursorB < b . size ( ) ; cursorB ++ ) { builder . add ( b . get ( cursorB ) ) ; } return makeCheckedFrom ( builder . build ( ) ) ; }
Union plus which adds the path to the current set of weights (this is the 'union' part of Union semiring)

@param a weight W
@param b weight W
@return