Computes the union of {@code assignments}. Equivalent to computing the
union iteratively using {@link #union(Assignment)}, but may be faster.

@param assignments
@return
322664
public static Assignment unionAll(Collection<Assignment> assignments) {
    int numVars = 0;
    for (Assignment assignment : assignments) {
      numVars += assignment.size();
    }

    int[] vars = new int[numVars];
    Object[] values = new Object[numVars];
    int numFilled = 0;
    for (Assignment assignment : assignments) {
      int[] assignmentVars = assignment.vars;
      Object[] assignmentValues = assignment.values;
      int numAssignmentVars = assignment.vars.length;
      for (int i = 0; i < numAssignmentVars; i++) {
        vars[numFilled] = assignmentVars[i];
        values[numFilled] = assignmentValues[i];
        numFilled++;
      }
    }
    Preconditions.checkState(numFilled == numVars);
    return Assignment.fromUnsortedArrays(vars, values);
  }
1060650
private Assignment initializeAssignment(FactorGraph factorGraph) {
		// Select the initial assignment. 
	  // TODO: Perform a search to find an outcome with nonzero probability.
	  
		Variable[] variables = factorGraph.getVariables().getVariablesArray();
		int[] varNums = factorGraph.getVariables().getVariableNumsArray();
		Object[] values = new Object[variables.length];
		for (int i = 0; i < variables.length; i++) {
			values[i] = variables[i].getArbitraryValue();
		}
		return Assignment.fromSortedArrays(varNums, values);
	}
603737
public Iterator<Assignment> assignmentIterator() {
    return Iterators.transform(weightBuilder.keyValueIterator(), new Function<KeyValue, Assignment>() {
      @Override
      public Assignment apply(KeyValue keyValue) {
        return getVars().intArrayToAssignment(keyValue.getKey());
      }
    });
  }
55371
public static <E> Set<E> unionView(final Set<? extends E> set1, final Set<? extends E> set2) {
		return Sets.union(set1, set2);
	}
780873
protected boolean concatOr( boolean... statements ) {
        boolean isTrue = statements[0];
        for( int i = 1; i < statements.length; i++ ) {
            isTrue = isTrue || statements[i];
        }
        return isTrue;
    }
238407
public <RT> Union<RT> unionAll(SubQueryExpression<RT>... sq) {
        unionAll = true;
        return innerUnion(sq);
    }
575070
private AssignmentInsn getEffectiveAssignmentInstruction(final Collection<AssignmentInsn> assignmentInstructions) {
        AssignmentInsn result = NullAssignmentInsn.getInstance();
        int maxInstructionNumber = -1;
        for (final AssignmentInsn assignmentInsn : assignmentInstructions) {
            final int indexOfAssignmentInstruction = assignmentInsn.getIndexWithinMethod();
            if (indexOfAssignmentInstruction > maxInstructionNumber) {
                maxInstructionNumber = indexOfAssignmentInstruction;
                result = assignmentInsn;
            }
        }
        return result;
    }
737220
public Collection<ExecutorDetails> getUnassignedExecutors(TopologyDetails topology) {
        if (topology == null) {
            return new ArrayList<>(0);
        }

        Collection<ExecutorDetails> ret = new HashSet<>(topology.getExecutors());

        SchedulerAssignment assignment = this.getAssignmentById(topology.getId());
        if (assignment != null) {
            Set<ExecutorDetails> assignedExecutors = assignment.getExecutors();
            ret.removeAll(assignedExecutors);
        }

        return ret;
    }
1064433
@Override
  public Choice<Unifier> visitCompoundAssignment(CompoundAssignmentTree assignOp, Unifier unifier) {
    return Choice.condition(getKind() == assignOp.getKind(), unifier)
        .thenChoose(unifications(getVariable(), assignOp.getVariable()))
        .thenChoose(unifications(getExpression(), assignOp.getExpression()));
  }
224244
public List<Type> union(List<Type> cl1, List<Type> cl2, BiPredicate<Type, Type> shouldSkip) {
        if (cl1.isEmpty()) {
            return cl2;
        } else if (cl2.isEmpty()) {
            return cl1;
        } else if (shouldSkip.test(cl1.head, cl2.head)) {
            return union(cl1.tail, cl2.tail, shouldSkip).prepend(cl1.head);
        } else if (cl1.head.tsym.precedes(cl2.head.tsym, this)) {
            return union(cl1.tail, cl2, shouldSkip).prepend(cl1.head);
        } else if (cl2.head.tsym.precedes(cl1.head.tsym, this)) {
            return union(cl1, cl2.tail, shouldSkip).prepend(cl2.head);
        } else {
            // unrelated types
            return union(cl1.tail, cl2, shouldSkip).prepend(cl1.head);
        }
    }
880635
@Override
   public DefaultConsistentHash union(DefaultConsistentHash dch1, DefaultConsistentHash dch2) {
      return dch1.union(dch2);
   }
152276
public int getAssignedNumWorkers(TopologyDetails topology) {
        SchedulerAssignment assignment = this.getAssignmentById(topology.getId());
        if (assignment == null) {
            return 0;
        }

        Set<WorkerSlot> slots = new HashSet<>();
        slots.addAll(assignment.getExecutorToSlot().values());

        return slots.size();
    }
153337
private void compileAssignment(Sequence sequence, TokenList tokens, TokenList.Token t0) {
        // see if it is assign or a range
        List<Variable> range = parseAssignRange(sequence, tokens, t0);

        TokenList.Token t1 = t0.next;
        if (t1.getType() != Type.SYMBOL || t1.getSymbol() != Symbol.ASSIGN)
            throw new ParseError("Expected assignment operator next");

        // Parse the right side of the equation
        TokenList tokensRight = tokens.extractSubList(t1.next, tokens.last);
        compileTokens(sequence, tokensRight);
        if (tokensRight.getLast().getType() != Type.VARIABLE)
            throw new RuntimeException("BUG the last token must be a variable");

        // copy the results into the output
        Variable variableRight = tokensRight.getFirst().getVariable();
        if (range == null) {
            // no range, so copy results into the entire output matrix
            sequence.output = createVariableInferred(t0, variableRight);
            sequence.addOperation(Operation.copy(variableRight, sequence.output));
        } else {
            // a sub-matrix range is specified.  Copy into that inner part
            if (t0.getType() == Type.WORD) {
                throw new ParseError("Can't do lazy variable initialization with submatrices. " + t0.getWord());
            }
            sequence.addOperation(Operation.copy(variableRight, t0.getVariable(), range));
        }
    }
574182
public Set<IndexedPredicate> variableToIndexedPredicateArray(int varNum, long[] assignments) {
    Set<IndexedPredicate> predicates = Sets.newHashSet();
    for (int i = 0; i < assignments.length; i++) {
      if (CcgParser.getAssignmentVarNum(assignments[i]) == varNum) {
        int predicateNum = CcgParser.getAssignmentPredicateNum(assignments[i]);
        int index = CcgParser.getAssignmentWordIndex(assignments[i]);
        predicates.add(new IndexedPredicate((String) dependencyHeadType.getValue(predicateNum), index));
      }
    }
    return predicates;
  }
1200866
public static final <T> Set<T> intersection(Collection<Set<T>> sets)
    {
        Set<T> set = union(sets);
        for (Set<T> s : sets)
        {
            set.retainAll(s);
        }
        return set;
    }
624185
public final Assignment union(Assignment other) {
    Preconditions.checkNotNull(other);
    if (other.size() == 0) {
      return this;
    } if (vars.length == 0) {
      return other;
    }

    // Merge varnums / values
    int[] otherNums = other.getVariableNumsArray();
    int[] myNums = getVariableNumsArray();
    Object[] otherVals = other.getValuesArray();
    Object[] myVals = getValuesArray();

    int[] mergedNums = new int[otherNums.length + myNums.length];
    Object[] mergedVals = new Object[otherNums.length + myNums.length];

    int i = 0;
    int j = 0;
    int numFilled = 0;
    while (i < otherNums.length && j < myNums.length) {
      if (otherNums[i] < myNums[j]) {
        mergedNums[numFilled] = otherNums[i];
        mergedVals[numFilled] = otherVals[i];
        i++;
        numFilled++;
      } else if (otherNums[i] > myNums[j]) {
        mergedNums[numFilled] = myNums[j];
        mergedVals[numFilled] = myVals[j];
        j++;
        numFilled++;
      } else {
        Preconditions.checkState(false, "Cannot combine non-disjoint assignments: %s with %s", this, other);
      }
    }
    // One list might still have elements in it.
    while (i < otherNums.length) {
      mergedNums[numFilled] = otherNums[i];
      mergedVals[numFilled] = otherVals[i];
      i++;
      numFilled++;
    }
    while (j < myNums.length) {
      mergedNums[numFilled] = myNums[j];
      mergedVals[numFilled] = myVals[j];
      j++;
      numFilled++;
    }
    Preconditions.checkState(numFilled == mergedNums.length);
    return Assignment.fromSortedArrays(mergedNums, mergedVals);
  }
349401
public List<Set<Integer>> clusters() {
        List<Set<Integer>> clusters = new ArrayList<Set<Integer>>();
        for (int c = 0; c < numClusters; ++c)
            clusters.add(new HashSet<Integer>());
        for (int i = 0; i < assignments.length; ++i)
            for (int k : assignments[i].assignments()) {
                // Check that the item was place in a cluster
                if (k >= 0)
                    clusters.get(k).add(i);
            }
        return clusters;
    }