// Copyright The OpenTelemetry Authors// SPDX-License-Identifier: Apache-2.0package attribute // import "go.opentelemetry.io/otel/attribute"// Iterator allows iterating over the set of attributes in order, sorted by// key.typeIteratorstruct { storage *Set idx int}// MergeIterator supports iterating over two sets of attributes while// eliminating duplicate values from the combined set. The first iterator// value takes precedence.typeMergeIteratorstruct { one oneIterator two oneIterator current KeyValue}type oneIterator struct { iter Iterator done bool attr KeyValue}// Next moves the iterator to the next position.// Next reports whether there are more attributes.func ( *Iterator) () bool { .idx++return .idx < .Len()}// Label returns current KeyValue. Must be called only after Next returns// true.//// Deprecated: Use Attribute instead.func ( *Iterator) () KeyValue {return .Attribute()}// Attribute returns the current KeyValue of the Iterator. It must be called// only after Next returns true.func ( *Iterator) () KeyValue { , := .storage.Get(.idx)return}// IndexedLabel returns current index and attribute. Must be called only// after Next returns true.//// Deprecated: Use IndexedAttribute instead.func ( *Iterator) () (int, KeyValue) {return .idx, .Attribute()}// IndexedAttribute returns current index and attribute. Must be called only// after Next returns true.func ( *Iterator) () (int, KeyValue) {return .idx, .Attribute()}// Len returns a number of attributes in the iterated set.func ( *Iterator) () int {return .storage.Len()}// ToSlice is a convenience function that creates a slice of attributes from// the passed iterator. The iterator is set up to start from the beginning// before creating the slice.func ( *Iterator) () []KeyValue { := .Len()if == 0 {returnnil } .idx = -1 := make([]KeyValue, 0, )for .Next() { = append(, .Attribute()) }return}// NewMergeIterator returns a MergeIterator for merging two attribute sets.// Duplicates are resolved by taking the value from the first set.func (, *Set) MergeIterator { := MergeIterator{one: makeOne(.Iter()),two: makeOne(.Iter()), }return}func makeOne( Iterator) oneIterator { := oneIterator{iter: , } .advance()return}func ( *oneIterator) () {if .done = !.iter.Next(); !.done { .attr = .iter.Attribute() }}// Next moves the iterator to the next position.// Next reports whether there is another attribute available.func ( *MergeIterator) () bool {if .one.done && .two.done {returnfalse }if .one.done { .current = .two.attr .two.advance()returntrue }if .two.done { .current = .one.attr .one.advance()returntrue }if .one.attr.Key == .two.attr.Key { .current = .one.attr// first iterator attribute value wins .one.advance() .two.advance()returntrue }if .one.attr.Key < .two.attr.Key { .current = .one.attr .one.advance()returntrue } .current = .two.attr .two.advance()returntrue}// Label returns the current value after Next() returns true.//// Deprecated: Use Attribute instead.func ( *MergeIterator) () KeyValue {return .current}// Attribute returns the current value after Next() returns true.func ( *MergeIterator) () KeyValue {return .current}
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.