// Union union another bitset to current bitset, expand the bitset if index out of length range
424034
func (s *Bitset) Union(b *Bitset) *Bitset {
	return s.bitsetOp(
		b,

		func(s, b *Bitset, length *uint) {
			bl, l := s.Length(0), *length

			if bl < l {
				s.unsetTop()
				s.Length(l)
			} else if bl > l {
				b.unsetTop()
			}
		},

		func(s, b *Bitset, index uint) {
			s.set[index] |= b.set[index]
		},
	)
}
458066
func (b *Bitset) Set(index, value int) bool {
	if index < b.size {
		b.setImpl(index, value)
		return true
	}
	return false
}
562008
func (b *OpenBitSet) intersect(other *OpenBitSet) {
	newLen := b.wlen
	if other.wlen < newLen {
		newLen = other.wlen
	}
	thisArr := b.bits
	otherArr := other.bits
	// testing against zero can be more efficient
	for pos := newLen - 1; pos >= 0; pos-- {
		thisArr[pos] &= otherArr[pos]
	}
	if b.wlen > newLen {
		// fill zeros from the new shorter length to the old length
		for i := newLen; i < b.wlen; i++ {
			b.bits[i] = 0
		}
	}
	b.wlen = newLen
}
490971
func unionBitmapArrayInPlace(a, b *Container) {
	a.unmapBitmap()
	bitmap := a.bitmap()
	for _, v := range b.array() {
		bitmap[v>>6] |= (uint64(1) << (v % 64))
	}
}
635273
func (set StringSet) Union(sset StringSet) StringSet {
	nset := NewStringSet()
	for k := range set {
		nset.Add(k)
	}

	for k := range sset {
		nset.Add(k)
	}

	return nset
}
1326007
func (set StringSet) Union(other StringSet) StringSet {
	unionedSet := NewStringSet()

	for elem := range set {
		unionedSet.Add(elem)
	}
	for elem := range other {
		unionedSet.Add(elem)
	}
	return unionedSet
}
197815
func (s *Bitset) unitOp(f func(*Bitset, int)) *Bitset {
	for i, n := 0, len(s.set); i < n; i++ {
		f(s, i)
	}

	return s
}
883450
func (s1 Int32) Union(s2 Int32) Int32 {
	result := NewInt32()
	for key := range s1 {
		result.Insert(key)
	}
	for key := range s2 {
		result.Insert(key)
	}
	return result
}
611625
func (s *Bitset) FlipAll() *Bitset {
	return s.unitOp(func(s *Bitset, i int) {
		s.set[i] = ^s.set[i]
	})
}
66932
func (t Term) UnionWithOpts(optArgs UnionOpts, args ...interface{}) Term {
	return constructMethodTerm(t, "Union", p.Term_UNION, args, optArgs.toMap())
}
243527
func Union(a, b interface{}) interface{} {
	chk := ty.Check(
		new(func(map[ty.A]bool, map[ty.A]bool) map[ty.A]bool),
		a, b)
	va, vb, tc := chk.Args[0], chk.Args[1], chk.Returns[0]

	vtrue := reflect.ValueOf(true)
	vc := reflect.MakeMap(tc)
	for _, vkey := range va.MapKeys() {
		vc.SetMapIndex(vkey, vtrue)
	}
	for _, vkey := range vb.MapKeys() {
		vc.SetMapIndex(vkey, vtrue)
	}
	return vc.Interface()
}
298615
func unionStringSets(a, b map[string]struct{}) map[string]struct{} {
	other := make(map[string]struct{})
	for k := range a {
		other[k] = struct{}{}
	}
	for k := range b {
		other[k] = struct{}{}
	}
	return other
}
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()))
}
433842
func (g1 *Virtual) Union(g2 *Virtual) *Virtual {
	return g1.union(g2, false)
}
1063308
func (c Circle) Union(d Circle) Circle {
	biggerC := maxCircle(c.Norm(), d.Norm())
	smallerC := minCircle(c.Norm(), d.Norm())

	// Get distance between centers
	dist := c.Center.To(d.Center).Len()

	// If the bigger Circle encompasses the smaller one, we have the result
	if dist+smallerC.Radius <= biggerC.Radius {
		return biggerC
	}

	// Calculate radius for encompassing Circle
	r := (dist + biggerC.Radius + smallerC.Radius) / 2

	// Calculate center for encompassing Circle
	theta := .5 + (biggerC.Radius-smallerC.Radius)/(2*dist)
	center := Lerp(smallerC.Center, biggerC.Center, theta)

	return Circle{
		Center: center,
		Radius: r,
	}
}
501444
func (s *rowSegment) Union(other *rowSegment) *rowSegment {
	data := s.data.Union(&other.data)

	return &rowSegment{
		data:  *data,
		shard: s.shard,
		n:     data.Count(),
	}
}
239170
func (b *BitSet) UnionCardinality(compare *BitSet) uint {
	panicIfNull(b)
	panicIfNull(compare)
	b, compare = sortByLength(b, compare)
	cnt := popcntOrSlice(b.set, compare.set)
	if len(compare.set) > len(b.set) {
		cnt += popcntSlice(compare.set[len(b.set):])
	}
	return uint(cnt)
}