docs: public final VariableNumMap union(VariableNumMap other) {
      if (other.size() == 0) {
        return this;
      } if (nums.length == 0) {
        return other;
      }
  
      int[] otherNums = other.nums;
      String[] otherNames = other.names;
      Variable[] otherVars = other.vars;
      int[] newNums = new int[nums.length + otherNums.length];
      String[] newNames = new String[nums.length + otherNums.length];
      Variable[] newVars = new Variable[nums.length + otherNums.length];
      int i = 0, j = 0, numFilled = 0;
      while (i < nums.length && j < otherNums.length) {
        if (nums[i] < otherNums[j]) {
          newNums[numFilled] = nums[i];
          newNames[numFilled] = names[i];
          newVars[numFilled] = vars[i];
          i++; numFilled++;
        } else if (nums[i] > otherNums[j]) {
          newNums[numFilled] = otherNums[j];
          newNames[numFilled] = otherNames[j];
          newVars[numFilled] = otherVars[j];
          j++; numFilled++;
        } else {
          // Equal. Both maps must have the same values for this variable
          Preconditions.checkArgument(names[i].equals(otherNames[j]));
          Preconditions.checkArgument(vars[i].getName().equals(otherVars[j].getName()));
          checkCompatibility(other);
  
          newNums[numFilled] = nums[i];
          newNames[numFilled] = names[i];
          newVars[numFilled] = vars[i];
          i++; j++; numFilled++;
        }
      }
  
      // Finish off any remaining entries.
      while (i < nums.length) {
        newNums[numFilled] = nums[i];
        newNames[numFilled] = names[i];
        newVars[numFilled] = vars[i];
        i++; numFilled++;
      }
  
      while (j < otherNums.length) {
        newNums[numFilled] = otherNums[j];
        newNames[numFilled] = otherNames[j];
        newVars[numFilled] = otherVars[j];
        j++; numFilled++;
      }
  
      return VariableNumMap.fromSortedArrays(newNums, newNames, newVars, numFilled);
    }