// Merge is used to merge two TLS configs together
323005
func (t *TLSConfig) Merge(b *TLSConfig) *TLSConfig {
	result := t.Copy()

	if b.EnableHTTP {
		result.EnableHTTP = true
	}
	if b.EnableRPC {
		result.EnableRPC = true
	}
	if b.VerifyServerHostname {
		result.VerifyServerHostname = true
	}
	if b.CAFile != "" {
		result.CAFile = b.CAFile
	}
	if b.CertFile != "" {
		result.CertFile = b.CertFile
	}
	if b.KeyFile != "" {
		result.KeyFile = b.KeyFile
	}
	if b.VerifyHTTPSClient {
		result.VerifyHTTPSClient = true
	}
	if b.RPCUpgradeMode {
		result.RPCUpgradeMode = true
	}
	if b.TLSCipherSuites != "" {
		result.TLSCipherSuites = b.TLSCipherSuites
	}
	if b.TLSMinVersion != "" {
		result.TLSMinVersion = b.TLSMinVersion
	}
	if b.TLSPreferServerCipherSuites {
		result.TLSPreferServerCipherSuites = true
	}
	return result
}
337378
func (f *BloomFilter) Merge(g *BloomFilter) error {
	// Make sure the m's and k's are the same, otherwise merging has no real use.
	if f.m != g.m {
		return fmt.Errorf("m's don't match: %d != %d", f.m, g.m)
	}

	if f.k != g.k {
		return fmt.Errorf("k's don't match: %d != %d", f.m, g.m)
	}

	f.b.InPlaceUnion(g.b)
	return nil
}
1333560
func (a *ServerConfig) Merge(b *ServerConfig) *ServerConfig {
	result := *a

	if b.Enabled {
		result.Enabled = true
	}
	if b.AuthoritativeRegion != "" {
		result.AuthoritativeRegion = b.AuthoritativeRegion
	}
	if b.BootstrapExpect > 0 {
		result.BootstrapExpect = b.BootstrapExpect
	}
	if b.DataDir != "" {
		result.DataDir = b.DataDir
	}
	if b.ProtocolVersion != 0 {
		result.ProtocolVersion = b.ProtocolVersion
	}
	if b.RaftProtocol != 0 {
		result.RaftProtocol = b.RaftProtocol
	}
	if b.NumSchedulers != nil {
		result.NumSchedulers = helper.IntToPtr(*b.NumSchedulers)
	}
	if b.NodeGCThreshold != "" {
		result.NodeGCThreshold = b.NodeGCThreshold
	}
	if b.JobGCThreshold != "" {
		result.JobGCThreshold = b.JobGCThreshold
	}
	if b.EvalGCThreshold != "" {
		result.EvalGCThreshold = b.EvalGCThreshold
	}
	if b.DeploymentGCThreshold != "" {
		result.DeploymentGCThreshold = b.DeploymentGCThreshold
	}
	if b.HeartbeatGrace != 0 {
		result.HeartbeatGrace = b.HeartbeatGrace
	}
	if b.MinHeartbeatTTL != 0 {
		result.MinHeartbeatTTL = b.MinHeartbeatTTL
	}
	if b.MaxHeartbeatsPerSecond != 0.0 {
		result.MaxHeartbeatsPerSecond = b.MaxHeartbeatsPerSecond
	}
	if b.RetryMaxAttempts != 0 {
		result.RetryMaxAttempts = b.RetryMaxAttempts
	}
	if b.RetryInterval != 0 {
		result.RetryInterval = b.RetryInterval
	}
	if b.RejoinAfterLeave {
		result.RejoinAfterLeave = true
	}
	if b.NonVotingServer {
		result.NonVotingServer = true
	}
	if b.RedundancyZone != "" {
		result.RedundancyZone = b.RedundancyZone
	}
	if b.UpgradeVersion != "" {
		result.UpgradeVersion = b.UpgradeVersion
	}
	if b.EncryptKey != "" {
		result.EncryptKey = b.EncryptKey
	}
	if b.ServerJoin != nil {
		result.ServerJoin = result.ServerJoin.Merge(b.ServerJoin)
	}

	// Add the schedulers
	result.EnabledSchedulers = append(result.EnabledSchedulers, b.EnabledSchedulers...)

	// Copy the start join addresses
	result.StartJoin = make([]string, 0, len(a.StartJoin)+len(b.StartJoin))
	result.StartJoin = append(result.StartJoin, a.StartJoin...)
	result.StartJoin = append(result.StartJoin, b.StartJoin...)

	// Copy the retry join addresses
	result.RetryJoin = make([]string, 0, len(a.RetryJoin)+len(b.RetryJoin))
	result.RetryJoin = append(result.RetryJoin, a.RetryJoin...)
	result.RetryJoin = append(result.RetryJoin, b.RetryJoin...)

	return &result
}
1253376
func (c1 *Config) Merge(c2 *Config) *Config {
	var result Config
	result.Providers = make(map[string]string)
	result.Provisioners = make(map[string]string)
	for k, v := range c1.Providers {
		result.Providers[k] = v
	}
	for k, v := range c2.Providers {
		if v1, ok := c1.Providers[k]; ok {
			log.Printf("[INFO] Local %s provider configuration '%s' overrides '%s'", k, v, v1)
		}
		result.Providers[k] = v
	}
	for k, v := range c1.Provisioners {
		result.Provisioners[k] = v
	}
	for k, v := range c2.Provisioners {
		if v1, ok := c1.Provisioners[k]; ok {
			log.Printf("[INFO] Local %s provisioner configuration '%s' overrides '%s'", k, v, v1)
		}
		result.Provisioners[k] = v
	}
	result.DisableCheckpoint = c1.DisableCheckpoint || c2.DisableCheckpoint
	result.DisableCheckpointSignature = c1.DisableCheckpointSignature || c2.DisableCheckpointSignature

	result.PluginCacheDir = c1.PluginCacheDir
	if result.PluginCacheDir == "" {
		result.PluginCacheDir = c2.PluginCacheDir
	}

	if (len(c1.Hosts) + len(c2.Hosts)) > 0 {
		result.Hosts = make(map[string]*ConfigHost)
		for name, host := range c1.Hosts {
			result.Hosts[name] = host
		}
		for name, host := range c2.Hosts {
			result.Hosts[name] = host
		}
	}

	if (len(c1.Credentials) + len(c2.Credentials)) > 0 {
		result.Credentials = make(map[string]map[string]interface{})
		for host, creds := range c1.Credentials {
			result.Credentials[host] = creds
		}
		for host, creds := range c2.Credentials {
			// We just clobber an entry from the other file right now. Will
			// improve on this later using the more-robust merging behavior
			// built in to HCL2.
			result.Credentials[host] = creds
		}
	}

	if (len(c1.CredentialsHelpers) + len(c2.CredentialsHelpers)) > 0 {
		result.CredentialsHelpers = make(map[string]*ConfigCredentialsHelper)
		for name, helper := range c1.CredentialsHelpers {
			result.CredentialsHelpers[name] = helper
		}
		for name, helper := range c2.CredentialsHelpers {
			result.CredentialsHelpers[name] = helper
		}
	}

	return &result
}
748047
func (a *Addresses) Merge(b *Addresses) *Addresses {
	result := *a

	if b.HTTP != "" {
		result.HTTP = b.HTTP
	}
	if b.RPC != "" {
		result.RPC = b.RPC
	}
	if b.Serf != "" {
		result.Serf = b.Serf
	}
	return &result
}
639256
func (e *ErrorRate) Merge(rate *ErrorRate) {
	e.QueryTotal += rate.QueryTotal
	e.ErrorTotal += rate.ErrorTotal
}
573260
func (uri *redirectURI) merge(m *model) {
	if len(m.scheme) > 0 {
		uri.scheme = m.scheme
	}
	if len(m.path) > 0 {
		uri.path = m.path
	}
	if len(m.port) > 0 {
		uri.port = m.port
	}
	if len(m.host) > 0 {
		uri.host = m.host
	}
}
673251
func (g *Git) Merge(arg string) *command.Model {
	return g.command("merge", arg)
}
1176805
func Merge(values ...Value) (Value, error) {
	var args []string
	for _, value := range values {
		args = append(args, value.String())
	}
	return Parse(args...)
}
1345284
func (a pgids) merge(b pgids) pgids {
	// Return the opposite slice if one is nil.
	if len(a) == 0 {
		return b
	}
	if len(b) == 0 {
		return a
	}
	merged := make(pgids, len(a)+len(b))
	mergepgids(merged, a, b)
	return merged
}
683620
func (c ConfigPolicyNode) Merge(n ctree.Node) ctree.Node {
	// Because Add only allows the ConfigPolicyNode type we
	// are safe to convert ctree.Node interface to ConfigPolicyNode
	cd := n.(*ConfigPolicyNode)
	// For the rules in the passed ConfigPolicyNode(converted) add each rule to
	// this ConfigPolicyNode overwriting where needed.
	no := NewPolicyNode()
	for _, r := range c.rules {
		no.Add(r)
	}

	for _, r := range cd.rules {

		no.Add(r)
	}
	// Return modified version of ConfigPolicyNode(as ctree.Node)
	return no
}
843892
func (x ContainerConfig) Merge(y ContainerConfig) ContainerConfig {
	x.TTY = x.TTY || y.TTY
	x.Stdin = x.Stdin || y.Stdin
	x.Data = x.Data || y.Data
	if y.Args != nil {
		x.Args = y.Args
	}
	env := make(map[string]string, len(x.Env)+len(y.Env))
	for k, v := range x.Env {
		env[k] = v
	}
	for k, v := range y.Env {
		env[k] = v
	}
	x.Env = env
	mounts := make([]Mount, 0, len(x.Mounts)+len(y.Mounts))
	mounts = append(mounts, x.Mounts...)
	mounts = append(mounts, y.Mounts...)
	x.Mounts = mounts
	volumes := make([]VolumeBinding, 0, len(x.Volumes)+len(y.Volumes))
	volumes = append(volumes, x.Volumes...)
	volumes = append(volumes, y.Volumes...)
	x.Volumes = volumes
	ports := make([]Port, 0, len(x.Ports)+len(y.Ports))
	ports = append(ports, x.Ports...)
	ports = append(ports, y.Ports...)
	x.Ports = ports
	if y.WorkingDir != "" {
		x.WorkingDir = y.WorkingDir
	}
	if y.Uid != nil {
		x.Uid = y.Uid
	}
	if y.Gid != nil {
		x.Gid = y.Gid
	}
	x.HostNetwork = x.HostNetwork || y.HostNetwork
	x.HostPIDNamespace = x.HostPIDNamespace || y.HostPIDNamespace
	return x
}
644273
func (g *Gauge) Merge(v *metricpb.GaugeValue) {
	g.value = v.Value
}
652144
func (d *NetworkDevice) merge(dev NetworkDevice) bool {
	changed := false
	if d.Port != dev.Port {
		changed = true
		d.Port = dev.Port
	}
	if d.Address != dev.Address {
		changed = true
		d.Address = dev.Address
	}
	if d.Info != dev.Info {
		changed = true
		d.Info = dev.Info
	}
	if d.Name != dev.Name {
		changed = true
		d.Name = dev.Name
	}

	return changed
}
1277163
func Merge(w io.Writer, opts *BuilderOpts, itrs []Iterator, f MergeFunc) error {
	builder, err := New(w, opts)
	if err != nil {
		return err
	}

	itr, err := NewMergeIterator(itrs, f)
	for err == nil {
		k, v := itr.Current()
		err = builder.Insert(k, v)
		if err != nil {
			return err
		}
		err = itr.Next()
	}

	if err != nil && err != ErrIteratorDone {
		return err
	}

	err = itr.Close()
	if err != nil {
		return err
	}

	err = builder.Close()
	if err != nil {
		return err
	}

	return nil
}
461360
func Merge(mapA map[string]interface{}, mapB map[string]interface{}) map[string]interface{} {
	for k, v := range mapA {
		mapB[k] = v
	}

	return mapB
}
788185
func Merge(c1, c2 *Config) (*Config, error) {
	c := new(Config)

	// Merge unknown keys
	unknowns := make(map[string]struct{})
	for _, k := range c1.unknownKeys {
		_, present := unknowns[k]
		if !present {
			unknowns[k] = struct{}{}
			c.unknownKeys = append(c.unknownKeys, k)
		}
	}
	for _, k := range c2.unknownKeys {
		_, present := unknowns[k]
		if !present {
			unknowns[k] = struct{}{}
			c.unknownKeys = append(c.unknownKeys, k)
		}
	}

	// Merge Atlas configuration. This is a dumb one overrides the other
	// sort of merge.
	c.Atlas = c1.Atlas
	if c2.Atlas != nil {
		c.Atlas = c2.Atlas
	}

	// Merge the Terraform configuration
	if c1.Terraform != nil {
		c.Terraform = c1.Terraform
		if c2.Terraform != nil {
			c.Terraform.Merge(c2.Terraform)
		}
	} else {
		c.Terraform = c2.Terraform
	}

	// NOTE: Everything below is pretty gross. Due to the lack of generics
	// in Go, there is some hoop-jumping involved to make this merging a
	// little more test-friendly and less repetitive. Ironically, making it
	// less repetitive involves being a little repetitive, but I prefer to
	// be repetitive with things that are less error prone than things that
	// are more error prone (more logic). Type conversions to an interface
	// are pretty low-error.

	var m1, m2, mresult []merger

	// Modules
	m1 = make([]merger, 0, len(c1.Modules))
	m2 = make([]merger, 0, len(c2.Modules))
	for _, v := range c1.Modules {
		m1 = append(m1, v)
	}
	for _, v := range c2.Modules {
		m2 = append(m2, v)
	}
	mresult = mergeSlice(m1, m2)
	if len(mresult) > 0 {
		c.Modules = make([]*Module, len(mresult))
		for i, v := range mresult {
			c.Modules[i] = v.(*Module)
		}
	}

	// Outputs
	m1 = make([]merger, 0, len(c1.Outputs))
	m2 = make([]merger, 0, len(c2.Outputs))
	for _, v := range c1.Outputs {
		m1 = append(m1, v)
	}
	for _, v := range c2.Outputs {
		m2 = append(m2, v)
	}
	mresult = mergeSlice(m1, m2)
	if len(mresult) > 0 {
		c.Outputs = make([]*Output, len(mresult))
		for i, v := range mresult {
			c.Outputs[i] = v.(*Output)
		}
	}

	// Provider Configs
	m1 = make([]merger, 0, len(c1.ProviderConfigs))
	m2 = make([]merger, 0, len(c2.ProviderConfigs))
	for _, v := range c1.ProviderConfigs {
		m1 = append(m1, v)
	}
	for _, v := range c2.ProviderConfigs {
		m2 = append(m2, v)
	}
	mresult = mergeSlice(m1, m2)
	if len(mresult) > 0 {
		c.ProviderConfigs = make([]*ProviderConfig, len(mresult))
		for i, v := range mresult {
			c.ProviderConfigs[i] = v.(*ProviderConfig)
		}
	}

	// Resources
	m1 = make([]merger, 0, len(c1.Resources))
	m2 = make([]merger, 0, len(c2.Resources))
	for _, v := range c1.Resources {
		m1 = append(m1, v)
	}
	for _, v := range c2.Resources {
		m2 = append(m2, v)
	}
	mresult = mergeSlice(m1, m2)
	if len(mresult) > 0 {
		c.Resources = make([]*Resource, len(mresult))
		for i, v := range mresult {
			c.Resources[i] = v.(*Resource)
		}
	}

	// Variables
	m1 = make([]merger, 0, len(c1.Variables))
	m2 = make([]merger, 0, len(c2.Variables))
	for _, v := range c1.Variables {
		m1 = append(m1, v)
	}
	for _, v := range c2.Variables {
		m2 = append(m2, v)
	}
	mresult = mergeSlice(m1, m2)
	if len(mresult) > 0 {
		c.Variables = make([]*Variable, len(mresult))
		for i, v := range mresult {
			c.Variables[i] = v.(*Variable)
		}
	}

	// Local Values
	// These are simpler than the other config elements because they are just
	// flat values and so no deep merging is required.
	if localsCount := len(c1.Locals) + len(c2.Locals); localsCount != 0 {
		// Explicit length check above because we want c.Locals to remain
		// nil if the result would be empty.
		c.Locals = make([]*Local, 0, len(c1.Locals)+len(c2.Locals))
		c.Locals = append(c.Locals, c1.Locals...)
		c.Locals = append(c.Locals, c2.Locals...)
	}

	return c, nil
}