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 label
Iterator allows iterating over the set of labels in order, sorted by key.
type Iterator struct {
	storage *Set
	idx     int
}
MergeIterator supports iterating over two sets of labels while eliminating duplicate values from the combined set. The first iterator value takes precedence.
Next moves the iterator to the next position. Returns false if there are no more labels.
func ( *Iterator) () bool {
	.idx++
	return .idx < .Len()
}
Label returns current KeyValue. Must be called only after Next returns true.
func ( *Iterator) () KeyValue {
	,  := .storage.Get(.idx)
	return 
}
Attribute is a synonym for Label().
func ( *Iterator) () KeyValue {
	return .Label()
}
IndexedLabel returns current index and label. Must be called only after Next returns true.
func ( *Iterator) () (int, KeyValue) {
	return .idx, .Label()
}
Len returns a number of labels in the iterator's `*Set`.
func ( *Iterator) () int {
	return .storage.Len()
}
ToSlice is a convenience function that creates a slice of labels from the passed iterator. The iterator is set up to start from the beginning before creating the slice.
func ( *Iterator) () []KeyValue {
	 := .Len()
	if  == 0 {
		return nil
	}
	.idx = -1
	 := make([]KeyValue, 0, )
	for .Next() {
		 = append(, .Label())
	}
	return 
}
NewMergeIterator returns a MergeIterator for merging two label sets Duplicates are resolved by taking the value from the first set.
func (,  *Set) MergeItererator {
	 := MergeItererator{
		one: makeOne(.Iter()),
		two: makeOne(.Iter()),
	}
	return 
}

func ( Iterator) oneIterator {
	 := oneIterator{
		iter: ,
	}
	.advance()
	return 
}

func ( *oneIterator) () {
	if .done = !.iter.Next(); !.done {
		.label = .iter.Label()
	}
}
Next returns true if there is another label available.
func ( *MergeItererator) () bool {
	if .one.done && .two.done {
		return false
	}
	if .one.done {
		.current = .two.label
		.two.advance()
		return true
	}
	if .two.done {
		.current = .one.label
		.one.advance()
		return true
	}
	if .one.label.Key == .two.label.Key {
		.current = .one.label // first iterator label value wins
		.one.advance()
		.two.advance()
		return true
	}
	if .one.label.Key < .two.label.Key {
		.current = .one.label
		.one.advance()
		return true
	}
	.current = .two.label
	.two.advance()
	return true
}
Label returns the current value after Next() returns true.
func ( *MergeItererator) () KeyValue {
	return .current