//
// UNION SELECT Statement ======================================================
//
549080
func Union(selects ...SelectStatement) UnionStatement {
	return &unionStatementImpl{
		selects: selects,
		limit:   -1,
		offset:  -1,
		unique:  true,
	}
}
52173
func (k *Keyspace) Union(a *Keyspace) *Keyspace {
	if a == nil && k == nil {
		return nil
	} else if a == nil {
		return k.Clone()
	} else if k == nil {
		return a.Clone()
	}
	aSI := k.Includes(a.Start) || k.End == a.Start
	aEI := k.Includes(a.End) || k.Start == a.End
	kSI := a.Includes(k.Start) || a.End == k.Start
	kEI := a.Includes(k.End) || a.Start == k.End

	switch {
	// Complete keyspace
	case aSI && aEI && kSI && kEI:
		return &Keyspace{Start: k.Start, End: k.Start - 1}

	// k encompasses a
	case aSI && aEI:
		return k.Clone()

	// a encompasses k
	case kSI && kEI:
		return a.Clone()

	// a.Start is in k
	case aSI:
		return &Keyspace{Start: k.Start, End: a.End}

	// a.End is in k
	case aEI:
		return &Keyspace{Start: a.Start, End: k.End}
	}
	return nil
}
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
}
1089313
func (term Range) Union(other Range) (union Range) {
	if term.IsEmpty() && other.IsEmpty() {
		union = Empty()
		return
	}
	if !term.IsEmpty() && term.Start.IsZero() {
		// Unbounded
	} else if !other.IsEmpty() && other.Start.IsZero() {
		// Unbounded
	} else if term.Start.Before(other.Start) {
		union.Start = term.Start
	} else {
		union.Start = other.Start
	}
	if !term.IsEmpty() && term.End.IsZero() {
		// Unbounded
	} else if !other.IsEmpty() && other.End.IsZero() {
		// Unbounded
	} else if term.End.After(other.End) {
		union.End = term.End
	} else {
		union.End = other.End
	}
	return
}
641210
func Union(set1, set2 Interface, sets ...Interface) Interface {
	u := set1.Copy()
	set2.Each(func(item interface{}) bool {
		u.Add(item)
		return true
	})
	for _, set := range sets {
		set.Each(func(item interface{}) bool {
			u.Add(item)
			return true
		})
	}

	return u
}
771462
func (h *HLL) Union(other *HLL) error {
	if h.P != other.P {
		return ErrSameP
	}
	if other.format == NORMAL {
		if h.format == SPARSE {
			h.ToNormal()
		}
		for i := uint(0); i < h.m1; i++ {
			if other.registers[i] > h.registers[i] {
				h.registers[i] = other.registers[i]
			}
		}
	} else if h.format == NORMAL && other.format == SPARSE {
		other.mergeSparse()
		for _, value := range other.sparseList.Data {
			index, rho := decodeHash(value, h.P)
			if h.registers[index] < rho {
				h.registers[index] = rho
			}
		}
	} else if h.format == SPARSE && other.format == SPARSE {
		h.mergeSparse()
		other.mergeSparse()
		h.sparseList.Merge(other.sparseList)
		h.checkModeChange()
	}
	return nil
}
656844
func (c *Configs) union(rhs *Configs) (*Configs, error) {
	// Merge the keys of ConfigVariables for each Configs instances. All the new
	// variables will become unbounded. This requires realigning the keys.
	configVariables := uniqueMergeSortedStrings(
		c.ConfigVariables, rhs.ConfigVariables)
	out := newConfigs(configVariables)
	byConfig := configPairs(append(
		c.expandConfigVariables(configVariables),
		rhs.expandConfigVariables(configVariables)...))
	if len(byConfig) == 0 {
		return out, nil
	}
	// Take union of ConfigSettings with the same configName (key),
	// in order left, right.
	// Thus, preserve the order between left, right while sorting.
	sort.Stable(byConfig)
	last := byConfig[0]
	for _, curr := range byConfig[1:] {
		if last.key.compare(curr.key) == 0 {
			val, err := last.value.union(curr.value)
			if err != nil {
				return out, err
			}
			last.value = val
		} else {
			out.setConfig(last.key, last.value)
			last = curr
		}
	}
	out.setConfig(last.key, last.value)
	return out, nil
}
281979
func (r Rect) Union(other Rect) Rect {
	return Rect{r.X.Union(other.X), r.Y.Union(other.Y)}
}
781407
func (statement *Statement) join(joinOP string, tablename interface{}, condition string, args ...interface{}) *Statement {
	join := statement.joinTables.New(statement)
	join.Operator = joinOP
	join.Table = ``
	join.Alias = ``
	join.ONStr = condition
	join.Args = args

	switch t := tablename.(type) {
	case []string:
		if len(t) > 1 {
			join.Table = statement.withPrefix(t[0])
			join.Alias = t[1]
		} else if len(t) == 1 {
			join.Table = statement.withPrefix(t[0])
		}
	case []interface{}:
		l := len(t)
		var table string
		if l > 0 {
			f := t[0]
			v := rValue(f)
			t := v.Type()
			if t.Kind() == reflect.String {
				table = f.(string)
			} else if t.Kind() == reflect.Struct {
				r := statement.Engine.autoMapType(v)
				table = r.Name
			} else {
				table = fmt.Sprintf("%v", f)
			}
			join.Table = statement.withPrefix(table)
		}
		if l > 1 {
			join.Alias = fmt.Sprintf("%v", t[1])
		}
	case core.SQL:
		join.SQLStr = joinOP + ` JOIN ` + string(t)
	case string:
		join.Table = statement.withPrefix(t)
	default:
		v := rValue(tablename)
		typ := v.Type()
		if typ.Kind() == reflect.Struct {
			r := statement.Engine.autoMapType(v)
			join.Table = r.Name
		} else {
			join.Table = statement.withPrefix(fmt.Sprintf("%v", tablename))
		}
	}
	return statement
}
34533
func Union(sets ...*Set) *Set {
	estimateIDs := 0
	estimateGroups := 0

	for _, s := range sets {
		if s == nil {
			continue
		}
		if s.All {
			return &Set{All: true}
		}
		if len(s.IDs) > estimateIDs {
			estimateIDs = len(s.IDs)
		}
		if len(s.Groups) > estimateGroups {
			estimateGroups = len(s.Groups)
		}
	}

	union := &Set{}
	if estimateIDs != 0 {
		union.IDs = make(identSet, estimateIDs)
	}
	if estimateGroups != 0 {
		union.Groups = make(groupSet, estimateGroups)
	}

	for _, s := range sets {
		if s == nil {
			continue
		}
		for ident := range s.IDs {
			union.IDs[ident] = struct{}{}
		}
		for group := range s.Groups {
			union.Groups[group] = struct{}{}
		}
	}

	return union
}
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()
}
657339
func (t Term) Union(args ...interface{}) Term {
	return constructMethodTerm(t, "Union", p.Term_UNION, args, map[string]interface{}{})
}
312821
func NewSelectQuery(builder Builder, db *DB) *SelectQuery {
	return &SelectQuery{
		builder:     builder,
		selects:     []string{},
		from:        []string{},
		join:        []JoinInfo{},
		orderBy:     []string{},
		groupBy:     []string{},
		union:       []UnionInfo{},
		limit:       -1,
		params:      Params{},
		FieldMapper: db.FieldMapper,
	}
}
945430
func (statement *Statement) Select(str string) *Statement {
	statement.selectStr = str
	return statement
}
342195
func (t *Table) Select(row, column int) *Table {
	t.selectedRow, t.selectedColumn = row, column
	return t
}
571096
func unionSelector(a, b Selector) Selector {
	return func(n *html.Node) bool {
		return a(n) || b(n)
	}
}
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]
		},
	)
}