Copyright The OpenTelemetry Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

package correlation

import 

type rawMap map[label.Key]label.Value
type keySet map[label.Key]struct{}
Map is an immutable storage for correlations.
type Map struct {
	m rawMap
}
MapUpdate contains information about correlation changes to be made.
DropSingleK contains a single key to be dropped from correlations. Use this to avoid an overhead of a slice allocation if there is only one key to drop.
DropMultiK contains all the keys to be dropped from correlations.
SingleKV contains a single key-value pair to be added to correlations. Use this to avoid an overhead of a slice allocation if there is only one key-value pair to add.
MultiKV contains all the key-value pairs to be added to correlations.
	MultiKV []label.KeyValue
}

func ( rawMap) Map {
	return Map{
		m: ,
	}
}
NewEmptyMap creates an empty correlations map.
func () Map {
	return newMap(nil)
}
NewMap creates a map with the contents of the update applied. In this function, having an update with DropSingleK or DropMultiK makes no sense - those fields are effectively ignored.
func ( MapUpdate) Map {
	return NewEmptyMap().Apply()
}
Apply creates a copy of the map with the contents of the update applied. Apply will first drop the keys from DropSingleK and DropMultiK, then add key-value pairs from SingleKV and MultiKV.
func ( Map) ( MapUpdate) Map {
	,  := getModificationSets()
	 := getNewMapSize(.m, , )

	 := make(rawMap, )
do not copy items we want to drop
		if ,  := [];  {
			continue
do not copy items we would overwrite
		if ,  := [];  {
			continue
		}
		[] = 
	}
	if .SingleKV.Key.Defined() {
		[.SingleKV.Key] = .SingleKV.Value
	}
	for ,  := range .MultiKV {
		[.Key] = .Value
	}
	if len() == 0 {
		 = nil
	}
	return newMap()
}

func ( MapUpdate) (,  keySet) {
	 := len(.DropMultiK)
	if .DropSingleK.Defined() {
		++
	}
	if  > 0 {
		 = make(map[label.Key]struct{}, )
		for ,  := range .DropMultiK {
			[] = struct{}{}
		}
		if .DropSingleK.Defined() {
			[.DropSingleK] = struct{}{}
		}
	}

	 := len(.MultiKV)
	if .SingleKV.Key.Defined() {
		++
	}
	if  > 0 {
		 = make(map[label.Key]struct{}, )
		for ,  := range .MultiKV {
			[.Key] = struct{}{}
		}
		if .SingleKV.Key.Defined() {
			[.SingleKV.Key] = struct{}{}
		}
	}

	return
}

func ( rawMap, ,  keySet) int {
	 := 0
	for  := range  {
		if ,  := []; ! {
			++
		}
	}
	for  := range  {
		if ,  := [];  {
			if ,  := []; ! {
				--
			}
		}
	}
	return len() + 
}
Value gets a value from correlations map and returns a boolean value indicating whether the key exist in the map.
func ( Map) ( label.Key) (label.Value, bool) {
	,  := .m[]
	return , 
}
HasValue returns a boolean value indicating whether the key exist in the map.
func ( Map) ( label.Key) bool {
	,  := .Value()
	return 
}
Len returns a length of the map.
func ( Map) () int {
	return len(.m)
}
Foreach calls a passed callback once on each key-value pair until all the key-value pairs of the map were iterated or the callback returns false, whichever happens first.
func ( Map) ( func(label.KeyValue) bool) {
	for ,  := range .m {
		if !(label.KeyValue{
			Key:   ,
			Value: ,
		}) {
			return
		}
	}