// Union returns a pointer to a new set containing the union of current set and other
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
}
441703
func (s *set) Merge(t Interface) {
	t.Each(func(item interface{}) bool {
		s.m[item] = keyExists
		return true
	})
}
103096
func (b *Builder) Union(unionTp string, unionCond *Builder) *Builder {
	var builder *Builder
	if b.optype != unionType {
		builder = &Builder{cond: NewCond()}
		builder.optype = unionType
		builder.dialect = b.dialect
		builder.selects = b.selects

		currentUnions := b.unions
		// erase sub unions (actually append to new Builder.unions)
		b.unions = nil

		for e := range currentUnions {
			currentUnions[e].builder.dialect = b.dialect
		}

		builder.unions = append(append(builder.unions, union{"", b}), currentUnions...)
	} else {
		builder = b
	}

	if unionCond != nil {
		if unionCond.dialect == "" && builder.dialect != "" {
			unionCond.dialect = builder.dialect
		}

		builder.unions = append(builder.unions, union{unionTp, unionCond})
	}

	return builder
}
1117208
func (t Type) Union() ([]string, bool) {
	if !t.IsUnion() {
		return nil, false
	}
	tips := []string{}
	for _, ut := range strings.Split(t.TypeString(), "|") {
		tips = append(tips, strings.TrimSpace(ut))
	}
	return tips, true
}
281979
func (r Rect) Union(other Rect) Rect {
	return Rect{r.X.Union(other.X), r.Y.Union(other.Y)}
}
48032
func Merge(coll1, coll2 []string) []string {
	m := map[string]struct{}{}
	for _, v := range append(coll1, coll2...) {
		m[v] = struct{}{}
	}
	r := make([]string, 0, len(m))
	for k := range m {
		r = append(r, k)
	}
	return r
}
367606
func (g *Geometry) Union(other *Geometry) (*Geometry, error) {
	return g.binaryTopo("Union", cGEOSUnion, other)
}
274710
func (t Any) Union(other Any) Any {
	if len(t) == 0 {
		return t
	}
	if len(other) == 0 {
		return other
	}
	cpy := make(Any, len(t))
	for i := range cpy {
		cpy[i] = t[i]
	}
	for i := range other {
		if !cpy.Contains(other[i]) {
			cpy = append(cpy, other[i])
		}
	}
	return cpy
}
1324096
func (rc *runContainer16) union(b *runContainer16) *runContainer16 {

	// rc is also known as 'a' here, but golint insisted we
	// call it rc for consistency with the rest of the methods.

	var m []interval16

	alim := int64(len(rc.iv))
	blim := int64(len(b.iv))

	var na int64 // next from a
	var nb int64 // next from b

	// merged holds the current merge output, which might
	// get additional merges before being appended to m.
	var merged interval16
	var mergedUsed bool // is merged being used at the moment?

	var cura interval16 // currently considering this interval16 from a
	var curb interval16 // currently considering this interval16 from b

	pass := 0
	for na < alim && nb < blim {
		pass++
		cura = rc.iv[na]
		curb = b.iv[nb]

		if mergedUsed {
			mergedUpdated := false
			if canMerge16(cura, merged) {
				merged = mergeInterval16s(cura, merged)
				na = rc.indexOfIntervalAtOrAfter(int64(merged.last())+1, na+1)
				mergedUpdated = true
			}
			if canMerge16(curb, merged) {
				merged = mergeInterval16s(curb, merged)
				nb = b.indexOfIntervalAtOrAfter(int64(merged.last())+1, nb+1)
				mergedUpdated = true
			}
			if !mergedUpdated {
				// we know that merged is disjoint from cura and curb
				m = append(m, merged)
				mergedUsed = false
			}
			continue

		} else {
			// !mergedUsed
			if !canMerge16(cura, curb) {
				if cura.start < curb.start {
					m = append(m, cura)
					na++
				} else {
					m = append(m, curb)
					nb++
				}
			} else {
				merged = mergeInterval16s(cura, curb)
				mergedUsed = true
				na = rc.indexOfIntervalAtOrAfter(int64(merged.last())+1, na+1)
				nb = b.indexOfIntervalAtOrAfter(int64(merged.last())+1, nb+1)
			}
		}
	}
	var aDone, bDone bool
	if na >= alim {
		aDone = true
	}
	if nb >= blim {
		bDone = true
	}
	// finish by merging anything remaining into merged we can:
	if mergedUsed {
		if !aDone {
		aAdds:
			for na < alim {
				cura = rc.iv[na]
				if canMerge16(cura, merged) {
					merged = mergeInterval16s(cura, merged)
					na = rc.indexOfIntervalAtOrAfter(int64(merged.last())+1, na+1)
				} else {
					break aAdds
				}
			}

		}

		if !bDone {
		bAdds:
			for nb < blim {
				curb = b.iv[nb]
				if canMerge16(curb, merged) {
					merged = mergeInterval16s(curb, merged)
					nb = b.indexOfIntervalAtOrAfter(int64(merged.last())+1, nb+1)
				} else {
					break bAdds
				}
			}

		}

		m = append(m, merged)
	}
	if na < alim {
		m = append(m, rc.iv[na:]...)
	}
	if nb < blim {
		m = append(m, b.iv[nb:]...)
	}

	res := &runContainer16{iv: m}
	return res
}
644953
func (i Interval) Union(other Interval) Interval {
	if i.IsEmpty() {
		return other
	}
	if other.IsEmpty() {
		return i
	}
	return Interval{math.Min(i.Lo, other.Lo), math.Max(i.Hi, other.Hi)}
}
1308811
func (g1 *Virtual) Join(g2 *Virtual, bridge EdgeSet) *Virtual {
	n := g1.order + g2.order
	t := g1.order // transpose
	switch {
	case n == 0:
		return null
	case g1.order == 0:
		return g2
	case g2.order == 0:
		return g1
	}

	if bridge.Cost == nil {
		bridge.Cost = zero
	}
	joinCost := func(v, w int) int64 {
		switch {
		case v < t && w < t:
			return g1.cost(v, w)
		case v >= t && w >= t:
			return g2.cost(v-t, w-t)
		default:
			return bridge.Cost(v, w)
		}
	}

	var noFilter bool
	if bridge.Keep == nil {
		noFilter = true
		bridge.Keep = alwaysEdge
	}
	s1 := bridge.From.And(Range(0, t))
	s2 := bridge.To.And(Range(t, g2.order+t))

	res := generic(n, joinCost, func(v, w int) (edge bool) {
		switch {
		case v < t && w < t:
			return g1.edge(v, w)
		case v >= t && w >= t:
			return g2.edge(v-t, w-t)
		case !bridge.Keep(v, w):
			return false
		default:
			return s1.Contains(v) && s2.Contains(w) ||
				s1.Contains(w) && s2.Contains(v)
		}
	})

	if noFilter {
		res.degree = func(v int) (deg int) {
			switch {
			case v < t:
				deg = g1.degree(v)
				if s1.Contains(v) {
					deg += s2.size()
				}
				return
			default:
				deg = g2.degree(v - t)
				if s2.Contains(v) {
					deg += s1.size()
				}
				return
			}
		}
	}

	res.visit = func(v int, a int, do func(w int, c int64) bool) (aborted bool) {
		if v < t {
			if g1.visit(v, a, do) {
				return true
			}
			if !s1.Contains(v) {
				return
			}
			for _, in := range s2.And(Range(a, n)).set {
				for w := in.a; w < in.b; w++ {
					if bridge.Keep(v, w) && do(w, bridge.Cost(v, w)) {
						return true
					}
				}
			}
			return
		}
		if s2.Contains(v) {
			for _, in := range s1.And(Range(a, n)).set {
				for w := in.a; w < in.b; w++ {
					if bridge.Keep(v, w) && do(w, bridge.Cost(v, w)) {
						return true
					}
				}
			}
		}
		return g2.visit(v-t, max(0, a-t), func(w int, c int64) bool {
			return do(w+t, c)
		})
	}
	return res
}
66932
func (t Term) UnionWithOpts(optArgs UnionOpts, args ...interface{}) Term {
	return constructMethodTerm(t, "Union", p.Term_UNION, args, optArgs.toMap())
}
1287591
func (s *set) Intersect(other Set) Set {
	o := other.(*set)
	n, m := s.Len(), o.Len()
	ss := s
	so := o
	if m < n {
		ss = o
		so = s
		n = m
	}

	r := newset(n)
	ss.Foreach(func(x *Term) {
		if so.Contains(x) {
			r.Add(x)
		}
	})
	return r
}
111277
func (s *Set) Union(t *Set) *Set {
	// Clone the current set into a new set
	outSet := s.Clone()

	// Enumerate and add all elements from the parameter set
	for _, e := range t.Enumerate() {
		outSet.Add(e)
	}

	return outSet
}
819211
func (set WordSet) Intersect(other WordSet) WordSet {
	intersection := NewWordSet()
	// loop over smaller set
	if set.Cardinality() < other.Cardinality() {
		for elem := range set {
			if other.Contains(elem) {
				intersection.Add(elem)
			}
		}
	} else {
		for elem := range other {
			if set.Contains(elem) {
				intersection.Add(elem)
			}
		}
	}
	return intersection
}
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()))
}
264528
func (b Bound) Union(other Bound) Bound {
	if other.IsEmpty() {
		return b
	}

	b = b.Extend(other.Min)
	b = b.Extend(other.Max)
	b = b.Extend(other.LeftTop())
	b = b.Extend(other.RightBottom())

	return b
}