// Merge two lists of UIDs. Duplicates will be dropped. Not stably ordered.
348890
func UIDListMerge(list1 []UID, list2 []UID) []UID {
	m := make(map[string]UID)
	for _, uid := range list1 {
		m[uid.String()] = uid
	}
	for _, uid := range list2 {
		m[uid.String()] = uid
	}
	res := make([]UID, 0)
	for _, uid := range m {
		res = append(res, uid)
	}
	return res
}
820075
func (s *SimpleMergePolicy) Merges(cellar *Cellar, segments segmentList) []*Merge {
	//rv := make([]*Merge, 0)
	var rv []*Merge
	consecutive := make(segmentList, 0)
	for i := len(segments) - 1; i >= 0; i-- {
		segment := segments[i]
		if segment.mergeInProgress == 0 {
			// insert, not append to keep the order the same (we're iterating reverse)
			consecutive = append(consecutive, nil)
			copy(consecutive[1:], consecutive[:])
			consecutive[0] = segment
			if len(consecutive) == 2 {
				rv = append(rv, &Merge{
					cellar:      cellar,
					sources:     consecutive,
					dropDeletes: (i == len(segments)-2), // if merging last 2 segments, we can drop deletes
				})
				consecutive = make(segmentList, 0)
			}
		} else {
			// found a segment with merge in progress, so start over
			consecutive = make(segmentList, 0)
		}
	}

	return rv
}
658282
func (b *BoolValue) Merge(onto *bool) {
	if b.v != nil {
		*onto = *(b.v)
	}
}
232141
func mergeInterfaces(a map[string]interface{}, b map[string]interface{}) (c map[string]interface{}, ok bool) {

	c = map[string]interface{}{}
	for k := range a {
		c[k] = a[k]
	}

	for k := range b {

		add := b[k]
		exist, ok := c[k]
		if !ok {
			c[k] = add
			continue
		}

		existObj, existOk := exist.(map[string]interface{})
		addObj, addOk := add.(map[string]interface{})
		if !existOk || !addOk {
			return nil, false
		}

		c[k], ok = mergeInterfaces(existObj, addObj)
		if !ok {
			return nil, false
		}
	}

	return c, true
}
894482
func (state *ServicesState) Merge(otherState *ServicesState) {
	for _, server := range otherState.Servers {
		for _, service := range server.Services {
			state.ServiceMsgs <- *service
		}
	}
}
391433
func merge(mapA, mapB map[string]interface{}) map[string]interface{} {
	result := make(map[string]interface{})
	for k, v := range mapA {
		result[k] = v
	}
	for k, v := range mapB {
		if _, ok := result[k]; !ok || result[k] == nil || result[k] == false {
			result[k] = v
		}
	}
	return result
}
1280801
func MergeSlices(args ...[]string) []string {
	all := map[string]struct{}{}
	for _, slice := range args {
		for _, v := range slice {
			all[v] = struct{}{}
		}
	}

	result := make([]string, 0, len(all))
	for k := range all {
		result = append(result, k)
	}
	sort.Strings(result)
	return result
}
1049154
func (s *StatsBase) Merge(o Stats) {
	s.F.SentBytes += o.SentBytes()
	s.F.SentMessages += o.SentMessages()
	s.F.DiscardedMessages += o.DiscardedMessages()
	s.F.Errors += o.Errors()
}
1093028
func (h *HyperLogLog) Merge(other *HyperLogLog) error {
	if h.m != other.m {
		return errors.New("number of registers must match")
	}

	for j, r := range other.registers {
		if r > h.registers[j] {
			h.registers[j] = r
		}
	}

	return nil
}
148870
func (r *results) merge(other *results) {
	if other == nil {
		return
	}

	r.mu.Lock()
	defer r.mu.Unlock()

	r.rowsAffected += other.rowsAffected
	if other.lastInsertID > r.lastInsertID {
		r.lastInsertID = other.lastInsertID
	}
	r.cumulativeDuration += other.duration
}
844165
func (s *JSONSchema) Merge(other *JSONSchema) {
	items := s.createMergeItems(other)
	for _, v := range items {
		if v.needed && v.b != nil {
			reflect.Indirect(reflect.ValueOf(v.a)).Set(reflect.ValueOf(v.b))
		}
	}

	for n, p := range other.Properties {
		if _, ok := s.Properties[n]; !ok {
			if s.Properties == nil {
				s.Properties = make(map[string]*JSONSchema)
			}
			s.Properties[n] = p
		}
	}

	for n, d := range other.Definitions {
		if _, ok := s.Definitions[n]; !ok {
			s.Definitions[n] = d
		}
	}

	for _, l := range other.Links {
		s.Links = append(s.Links, l)
	}

	for _, r := range other.Required {
		s.Required = append(s.Required, r)
	}
}
1055491
func (e PrimitiveElement) Merge(v Strategy) (Result, error) {
	return v.MergePrimitive(e)
}
937351
func Merge(its ...Postings) Postings {
	if len(its) == 0 {
		return EmptyPostings()
	}
	if len(its) == 1 {
		return its[0]
	}

	p, ok := newMergedPostings(its)
	if !ok {
		return EmptyPostings()
	}
	return p
}
1098542
func Merge(dst, src1, src2 string) {
	ix1 := Open(src1)
	ix2 := Open(src2)
	paths1 := ix1.Paths()
	paths2 := ix2.Paths()

	// Build docid maps.
	var i1, i2, new uint32
	var map1, map2 []idrange
	for _, path := range paths2 {
		// Determine range shadowed by this path.
		old := i1
		for i1 < uint32(ix1.numName) && ix1.Name(i1) < path {
			i1++
		}
		lo := i1
		limit := path[:len(path)-1] + string(path[len(path)-1]+1)
		for i1 < uint32(ix1.numName) && ix1.Name(i1) < limit {
			i1++
		}
		hi := i1

		// Record range before the shadow.
		if old < lo {
			map1 = append(map1, idrange{old, lo, new})
			new += lo - old
		}

		// Determine range defined by this path.
		// Because we are iterating over the ix2 paths,
		// there can't be gaps, so it must start at i2.
		if i2 < uint32(ix2.numName) && ix2.Name(i2) < path {
			panic("merge: inconsistent index")
		}
		lo = i2
		for i2 < uint32(ix2.numName) && ix2.Name(i2) < limit {
			i2++
		}
		hi = i2
		if lo < hi {
			map2 = append(map2, idrange{lo, hi, new})
			new += hi - lo
		}
	}

	if i1 < uint32(ix1.numName) {
		map1 = append(map1, idrange{i1, uint32(ix1.numName), new})
		new += uint32(ix1.numName) - i1
	}
	if i2 < uint32(ix2.numName) {
		panic("merge: inconsistent index")
	}
	numName := new

	ix3 := bufCreate(dst)
	ix3.writeString(magic)

	// Merged list of paths.
	pathData := ix3.offset()
	mi1 := 0
	mi2 := 0
	last := "\x00" // not a prefix of anything
	for mi1 < len(paths1) || mi2 < len(paths2) {
		var p string
		if mi2 >= len(paths2) || mi1 < len(paths1) && paths1[mi1] <= paths2[mi2] {
			p = paths1[mi1]
			mi1++
		} else {
			p = paths2[mi2]
			mi2++
		}
		if strings.HasPrefix(p, last) {
			continue
		}
		last = p
		ix3.writeString(p)
		ix3.writeString("\x00")
	}
	ix3.writeString("\x00")

	// Merged list of names.
	nameData := ix3.offset()
	nameIndexFile := bufCreate("")
	new = 0
	mi1 = 0
	mi2 = 0
	for new < numName {
		if mi1 < len(map1) && map1[mi1].new == new {
			for i := map1[mi1].lo; i < map1[mi1].hi; i++ {
				name := ix1.Name(i)
				nameIndexFile.writeUint32(ix3.offset() - nameData)
				ix3.writeString(name)
				ix3.writeString("\x00")
				new++
			}
			mi1++
		} else if mi2 < len(map2) && map2[mi2].new == new {
			for i := map2[mi2].lo; i < map2[mi2].hi; i++ {
				name := ix2.Name(i)
				nameIndexFile.writeUint32(ix3.offset() - nameData)
				ix3.writeString(name)
				ix3.writeString("\x00")
				new++
			}
			mi2++
		} else {
			panic("merge: inconsistent index")
		}
	}
	if new*4 != nameIndexFile.offset() {
		panic("merge: inconsistent index")
	}
	nameIndexFile.writeUint32(ix3.offset())

	// Merged list of posting lists.
	postData := ix3.offset()
	var r1 postMapReader
	var r2 postMapReader
	var w postDataWriter
	r1.init(ix1, map1)
	r2.init(ix2, map2)
	w.init(ix3)
	for {
		if r1.trigram < r2.trigram {
			w.trigram(r1.trigram)
			for r1.nextId() {
				w.fileid(r1.fileid)
			}
			r1.nextTrigram()
			w.endTrigram()
		} else if r2.trigram < r1.trigram {
			w.trigram(r2.trigram)
			for r2.nextId() {
				w.fileid(r2.fileid)
			}
			r2.nextTrigram()
			w.endTrigram()
		} else {
			if r1.trigram == ^uint32(0) {
				break
			}
			w.trigram(r1.trigram)
			r1.nextId()
			r2.nextId()
			for r1.fileid < ^uint32(0) || r2.fileid < ^uint32(0) {
				if r1.fileid < r2.fileid {
					w.fileid(r1.fileid)
					r1.nextId()
				} else if r2.fileid < r1.fileid {
					w.fileid(r2.fileid)
					r2.nextId()
				} else {
					panic("merge: inconsistent index")
				}
			}
			r1.nextTrigram()
			r2.nextTrigram()
			w.endTrigram()
		}
	}

	// Name index
	nameIndex := ix3.offset()
	copyFile(ix3, nameIndexFile)

	// Posting list index
	postIndex := ix3.offset()
	copyFile(ix3, w.postIndexFile)

	ix3.writeUint32(pathData)
	ix3.writeUint32(nameData)
	ix3.writeUint32(postData)
	ix3.writeUint32(nameIndex)
	ix3.writeUint32(postIndex)
	ix3.writeString(trailerMagic)
	ix3.flush()

	os.Remove(nameIndexFile.name)
	os.Remove(w.postIndexFile.name)
}
332649
func (s *rowSegment) Merge(other *rowSegment) {
	s.ensureWritable()

	itr := other.data.Iterator()
	for v, eof := itr.Next(); !eof; v, eof = itr.Next() {
		s.SetBit(v)
	}
}
1229272
func mergeThresholds(inputsA []evictionapi.Threshold, inputsB []evictionapi.Threshold) []evictionapi.Threshold {
	results := inputsA
	for _, threshold := range inputsB {
		if !hasThreshold(results, threshold) {
			results = append(results, threshold)
		}
	}
	return results
}
461360
func Merge(mapA map[string]interface{}, mapB map[string]interface{}) map[string]interface{} {
	for k, v := range mapA {
		mapB[k] = v
	}

	return mapB
}