Gets the union of this set and the given set(s) and returns it
@param mixed $set , $set2 The sets to compare to, either ARedisSet instances or their names
@return array the union of this set and the given sets
327634
public function union ($set) {
        if (is_array ($set)) {
            $parameters = $set;
        } else {
            $parameters = func_get_args ();
        }
        foreach ($parameters as $n => $set) {
            if ($set instanceof ARedisSet) {
                $parameters[$n] = $set->name;
            }
        }
        array_unshift ($parameters , $this->name);
        return call_user_func_array (array(
            $this->getConnection ()->getSlave(),
            "sunion"
        ) , $parameters);
    }
703662
function(and1, and2) {
			var union1 = set.union(and1, and2.values[0]);
			var union2 = set.union(and1, and2.values[1]);

			if (isAndOrOr(union1) || isAndOrOr(union2)) {
				// try the other direction
				union1 = set.union(and2, and1.values[0]);
				union2 = set.union(and2, and1.values[1]);
			}
			if (isAndOrOr(union1) || isAndOrOr(union2)) {
				return new is.Or([and1, and2]);
			} else {
				return set.intersection(union1, union2);
			}

			/*
			var combo1 = [
					set.union(and1.values[0], and2.values[0]),
					set.union(and1.values[1], and2.values[1])
				],
				combo2 = [
					set.union(and1.values[0], and2.values[1]),
					set.union(and1.values[1], and2.values[0])
				];
			if(combo1.every(isUniversal)) {
				return set.intersection.apply(set, combo2);
			}
			if(combo2.every(isUniversal)) {
				return set.intersection.apply(set, combo1);
			}
			return new is.Or([and1, and2]);*/
		}
831993
public function toASN1(): Set
    {
        $elements = array_map(
            function (Attribute $attr) {
                return $attr->toASN1();
            }, array_values($this->_attributes));
        $set = new Set(...$elements);
        return $set->sortedSetOf();
    }
309734
public static <E> Set<E> union(final Set<? extends E> set1, final Set<? extends E> set2) {
        checkArgumentNotNull(set1, "set1");
        checkArgumentNotNull(set2, "set2");

        // Set 2 minus set 1
        final Set<E> difference = new HashSet<>(set2);
        difference.removeAll(set1);
        // Following stream does not compile on some JDKs
        // See also https://bugs.openjdk.java.net/browse/JDK-8051443
        // set2.stream().filter((e) -> !set1.contains(e)).collect(Collectors.toSet());

        return new AbstractSet<E>() {

            @Override
            public Iterator<E> iterator() {
                final Iterator<E> iterator = Iterators.concat(ImmutableList.of(set1.iterator(), difference.iterator()).iterator());
                // Remove operation is not supported by default
                return new Iterator<E>() {
                    @Override
                    public boolean hasNext() {
                        return iterator.hasNext();
                    }

                    @Override
                    public E next() {
                        return iterator.next();
                    }
                };
            }

            @Override
            public int size() {
                return set1.size() + difference.size();
            }

            @Override
            public boolean isEmpty() {
                return set1.isEmpty() && difference.isEmpty();
            }

            @Override
            public boolean contains(Object o) {
                return set1.contains(o) || difference.contains(o);
            }
        };
    }
1324598
public static final <T> Set<T> union(Collection<Set<T>> sets)
    {
        Set<T> set = new HashSet<>();
        for (Set<T> s : sets)
        {
            set.addAll(s);
        }
        return set;
    }
840106
public static function keyOf(array $set, $match) {
        $return = null;
        $isArray = array();

        foreach ($set as $key => $value) {
            if ($value === $match) {
                $return = $key;
            }

            if (is_array($value)) {
                $isArray[] = $key;
            }
        }

        if (!$return && $isArray) {
            foreach ($isArray as $key) {
                if ($value = static::keyOf($set[$key], $match)) {
                    $return = $key . '.' . $value;
                }
            }
        }

        return $return;
    }
1058877
public function diff( \PhpSets\Set $set ) {
        $entries = $this->entries();
        $iterator = $set->entries();
        $intersect = new \PhpSets\Set;

        // check $set values
        while ( $entries->valid() ) {
            if ( ! $set->has( $entries->current() ) ) {
                $intersect->add( $entries->current() );
            }

            $entries->next();
        }

        // check $additionalSet values
        while ( $iterator->valid() ) {
            if ( ! $this->has( $iterator->current() ) ) {
                $intersect->add( $iterator->current() );
            }

            $iterator->next();
        }

        return $intersect;
    }
458966
public function xor(Set $set): SetInterface
    {
        $set = new \DS\Set($set);
        $items = $this->items->xor($set);

        return $this->duplicate($items);
    }
1224780
public function union($fields, $second)
    {
        return array_map(
            'unserialize', array_unique(
                array_map(
                    'serialize', array_merge(
                        $this->select($fields),
                        $second->select($fields)
                    )
                )
            )
        );
    }
495926
public static function union(Set $a, Set $b) : Set
    {
        return new self(array_merge($a->toArray(), $b->toArray()));
    }
429455
public static <A> Set<A> intersection(Set<A> first, Set<A> second) {

        HashSet<A> result = new HashSet<A>(first);
        result.retainAll(second);
        return result;
    }
1286217
public static function expand(array $set) {
        $data = array();

        foreach ($set as $key => $value) {
            $data = static::insert($data, $key, $value);
        }

        return $data;
    }
234338
public function enumerateSets()
    {
        foreach ($this->sets as $set) {
            $value = $set->getValue();
            $key = $set->getProperty();
            $section = $set->getSection();
            $operation = $set->getOperation();
            if ($value !== null) {
                try {
                    $this->ini->set($section, $key, $value);
                    $this->logDebugOrMore("[$section] $key set to $value");
                } catch (Exception $ex) {
                    $this->log(
                        "Error setting value for section '" . $section .
                        "', key '" . $key ."'",
                        Project::MSG_ERR
                    );
                    $this->logDebugOrMore($ex->getMessage());
                }
            } elseif ($operation !== null) {
                $v = $this->ini->get($section, $key);
                // value might be wrapped in quotes with a semicolon at the end
                if (!is_numeric($v)) {
                    if (preg_match('/^"(\d*)";?$/', $v, $match)) {
                        $v = $match[1];
                    } elseif (preg_match("/^'(\d*)';?$/", $v, $match)) {
                        $v = $match[1];
                    } else {
                        $this->log(
                            "Value $v is not numeric. Skipping $operation operation."
                        );
                        continue;
                    }
                }
                if ($operation == '+') {
                    ++$v;
                } elseif ($operation == '-') {
                    --$v;
                } else {
                    if (($operation != '-') && ($operation != '+')) {
                        $msg = "Unrecognised operation $operation";
                        if ($this->haltonerror) {
                            throw new BuildException($msg);
                        }
                        $this->log($msg, Project::MSG_ERR);
                    }
                }
                try {
                    $this->ini->set($section, $key, $v);
                    $this->logDebugOrMore("[$section] $key set to $v");
                } catch (Exception $ex) {
                    $this->log(
                        "Error setting value for section '" . $section .
                        "', key '" . $key ."'"
                    );
                    $this->logDebugOrMore($ex->getMessage());
                }
            } else {
                $this->log(
                    "Set: value and operation are both not set",
                    Project::MSG_ERR
                );
            }
        }
    }
1065653
Set<E> union(final SmallSet<E> s) {
        if ((s.e1 == e1 && s.e2 == e2) || (s.e1 == e2 && s.e2 == e1)) {
            return this; // if the two sets are equal, return this
        }
        if (s.e1 == null) {
            return this; // if s is empty, return this
        }
        if (e1 == null) {
            return s; // if this is empty, return s
        }
        if (s.e2 == null) { // s contains exactly one element
            if (e2 == null) {
                return new SmallSet<E>(e1, s.e1); // necessarily e1 != s.e1
            } else if (s.e1 == e1 || s.e1 == e2) { // s is included in this
                return this;
            }
        }
        if (e2 == null) { // this contains exactly one element
            // if (s.e2 == null) { // cannot happen
            // return new SmallSet(e1, s.e1); // necessarily e1 != s.e1
            // } else
            if (e1 == s.e1 || e1 == s.e2) { // this in included in s
                return s;
            }
        }
        // here we know that there are at least 3 distinct elements
        HashSet<E> r = new HashSet<E>(4);
        r.add(e1);
        if (e2 != null) {
            r.add(e2);
        }
        r.add(s.e1);
        if (s.e2 != null) {
            r.add(s.e2);
        }
        return r;
    }
607977
public function insertMany(array $sets)
    {
        if (count($sets)) {
            if (method_exists($this, 'insertRecordSets')) {
                foreach ($sets as $set) {
                    $this->insertRecordSets($set);
                    if ($this->recordOrdering === true && empty($sets[ 'record_ordering' ])) {
                        $set[ 'record_ordering' ] = $this->getRecordOrdering($this->table);
                    }
                }
            }

            if (method_exists($this, 'beforeInsertMany')) {
                $this->beforeInsertMany($sets);
            }

            if ($this->qb->table($this->table)->insertBatch($sets)) {
                if (method_exists($this, 'afterInsertMany')) {
                    return $this->afterInsertMany();
                }

                return $this->db->getAffectedRows();
            }
        }

        return false;
    }
363572
public static function merge($one, $two) 
    {
        $elements = $one->elements;
        foreach($two->elements as $node) {
            $exists = false;
            foreach($elements as $node2) {
                if ($node2->isSameNode($node)) {
                    $exists = true;
                }
            }
            if (! $exists) {
                $elements[] = $node;
            }
        }
        return $elements;
        //        $one = $one->newInstance();
        //        $one->elements = $elements;
        //        return $one;
    }
392948
public function getSubset($prop, $keys) {
		if (is_string($keys))
			$keys = \Base::instance()->split($keys);
		if (!is_array($keys))
			trigger_error(sprintf(self::E_SubsetKeysValue,gettype($keys)),E_USER_ERROR);
		if (!$this->hasRelSet($prop) || !($relSet = $this->getRelSet($prop)))
			return null;
		foreach ($keys as &$key) {
			if ($key instanceof \MongoId || $key instanceof \MongoDB\BSON\ObjectId)
				$key = (string) $key;
			unset($key);
		}
		return array_values(array_intersect_key($relSet, array_flip($keys)));
	}