// Union returns a new set with all items in both sets.
511118
func (set LiteralFieldSet) Union(other LiteralFieldSet) LiteralFieldSet {
	unionedSet := NewLiteralFieldSet()

	for elem := range set {
		unionedSet.Add(elem)
	}
	for elem := range other {
		unionedSet.Add(elem)
	}
	return unionedSet
}
1022057
func (s *SyncedSet) Items() (c chan interface{}) {
	c = make(chan interface{})
	go func() {
		s.RLock()
		defer s.RUnlock()
		defer close(c)
		for k := range s.set {
			c <- k
		}
	}()
	return c

}
441703
func (s *set) Merge(t Interface) {
	t.Each(func(item interface{}) bool {
		s.m[item] = keyExists
		return true
	})
}
103482
func (t *Function) Union(other *Function) *Function {
	if other == nil {
		return t
	} else if t == nil {
		return other
	}
	a := t.Args()
	b := other.Args()
	if len(a) != len(b) {
		return nil
	}
	args := make([]Type, len(a))
	for i := range a {
		args[i] = Or(a[i], b[i])
	}

	return NewFunction(args, Or(t.Result(), other.Result()))
}
476229
func (s *OrderedSet) Intersect(other *OrderedSet) *OrderedSet {
	intersection := NewOrderedSetWithCapacity(MinInt(
		s.Cardinality(), other.Cardinality()))

	if s.Cardinality() < other.Cardinality() {
		for _, elem := range s.s {
			if other.Contains(elem) {
				intersection.Add(elem)
			}
		}
	} else {
		for _, elem := range other.s {
			if s.Contains(elem) {
				intersection.Add(elem)
			}
		}
	}

	return intersection
}
456531
func (s *Set) Intersection(other *Set) *Set {
	result := new(Set)
	if s == nil {
		return result
	}
	if other != nil {
		for _, v := range s.m {
			if other.Include(v) {
				result.Add(v)
			}
		}
	}

	return result
}
442939
func (g1 *Virtual) union(g2 *Virtual, cost bool) *Virtual {
	switch {
	case g1.order == 0:
		if cost {
			return g2
		}
		return g2.AddCost(0)
	case g2.order == 0:
		if cost {
			return g1
		}
		return g1.AddCost(0)
	}

	newCost := zero
	if cost {
		newCost = func(v, w int) int64 {
			if g2.edge(v, w) && !g1.edge(v, w) {
				return g2.cost(v, w)
			}
			return g1.cost(v, w)
		}
	}
	var res *Virtual
	switch {
	case g1.order == g2.order:
		res = generic(g1.order, newCost, func(v, w int) bool {
			return g1.edge(v, w) || g2.edge(v, w)
		})
	case g1.order < g2.order:
		res = generic(g2.order, newCost, func(v, w int) bool {
			return v < g1.order && w < g1.order && g1.edge(v, w) || g2.edge(v, w)
		})
	default:
		res = generic(g1.order, newCost, func(v, w int) bool {
			return v < g2.order && w < g2.order && g2.edge(v, w) || g1.edge(v, w)
		})
	}

	res.visit = func(v int, a int, do func(w int, c int64) bool) (aborted bool) {
		next := 0
		if v < g1.order && g1.visit(v, a, func(w int, c int64) (skip bool) {
			// First all neighbors from g2 that are less than w...
			if next != w && v < g2.order && a <= w {
				if more := false; g2.visit(v, max(next, a), func(w0 int, c0 int64) (skip bool) {
					if w0 >= w {
						more, skip = true, true
						return
					}
					if cost {
						return do(w0, c0)
					}
					return do(w0, 0)
				}) && !more {
					return true
				}
			}
			// ...then w.
			switch {
			case cost && do(w, c):
				return true
			case !cost && do(w, 0):
				return true
			}
			next = w + 1
			return
		}) {
			return true
		}
		// When done with g1, produce any leftovers from g2.
		return v < g2.order && g2.visit(v, max(next, a), func(w int, c int64) (skip bool) {
			if cost {
				return do(w, c)
			}
			return do(w, 0)
		})
	}
	return res
}
1197542
func Union(a, b [][]byte) [][]byte {
	n := len(b)
	if len(a) > len(b) {
		n = len(a)
	}
	other := make([][]byte, 0, n)

	for {
		if len(a) > 0 && len(b) > 0 {
			if cmp := bytes.Compare(a[0], b[0]); cmp == 0 {
				other, a, b = append(other, a[0]), a[1:], b[1:]
			} else if cmp == -1 {
				other, a = append(other, a[0]), a[1:]
			} else {
				other, b = append(other, b[0]), b[1:]
			}
		} else if len(a) > 0 {
			other, a = append(other, a[0]), a[1:]
		} else if len(b) > 0 {
			other, b = append(other, b[0]), b[1:]
		} else {
			return other
		}
	}
}
1358402
func (s CPUSet) Union(s2 CPUSet) CPUSet {
	b := NewBuilder()
	for cpu := range s.elems {
		b.Add(cpu)
	}
	for cpu := range s2.elems {
		b.Add(cpu)
	}
	return b.Result()
}
681769
func (s *SelectQuery) Union(q *Query) *SelectQuery {
	s.union = append(s.union, UnionInfo{false, q})
	return s
}
1096068
func Union(data sort.Interface, pivot int) (size int) {
	// BUG(extemporalgenome): Union currently uses a multi-pass implementation

	sort.Sort(data)
	return Uniq(data)
}
518046
func (s *Set) Merge(t Interface) {
	s.l.Lock()
	defer s.l.Unlock()

	t.Each(func(item interface{}) bool {
		s.m[item] = keyExists
		return true
	})
}
519716
func (s *SyncedSet) Union(other *SyncedSet) *SyncedSet {
	newSet := NewSyncedSet()
	for elt := range s.set {
		newSet.Add(elt)
	}
	for elt := range other.set {
		newSet.Add(elt)
	}
	return &newSet
}
663810
func (q Query) Union(q2 Query) Query {
	return Query{
		Iterate: func() Iterator {
			next := q.Iterate()
			next2 := q2.Iterate()

			set := make(map[interface{}]bool)
			use1 := true

			return func() (item interface{}, ok bool) {
				if use1 {
					for item, ok = next(); ok; item, ok = next() {
						if _, has := set[item]; !has {
							set[item] = true
							return
						}
					}

					use1 = false
				}

				for item, ok = next2(); ok; item, ok = next2() {
					if _, has := set[item]; !has {
						set[item] = true
						return
					}
				}

				return
			}
		},
	}
}
71934
func (s Set) Union(other Set) Set {
	ret := make(Set, len(s))
	for k := range s {
		ret[k] = struct{}{}
	}
	for k := range other {
		ret[k] = struct{}{}
	}
	return ret
}
1048482
func (set IdentifierSet) Union(other IdentifierSet) IdentifierSet {
	unionedSet := NewIdentifierSet()

	for elem := range set {
		unionedSet.Add(elem)
	}
	for elem := range other {
		unionedSet.Add(elem)
	}
	return unionedSet
}
156899
func (r Rect) Union(s Rect) Rect {
	return R(
		math.Min(r.Min.X, s.Min.X),
		math.Min(r.Min.Y, s.Min.Y),
		math.Max(r.Max.X, s.Max.X),
		math.Max(r.Max.Y, s.Max.Y),
	)
}