blob: 7628ad0df8aa67c15b16c79a9fbc7b96255764cf [file] [log] [blame]
/*
* Copyright 2022-present Open Networking Foundation
* 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 format
import "sort"
// Pair structure
type Pair struct {
Value interface{}
Key string
}
// PairList type
type PairList []Pair
func (p PairList) Len() int { return len(p) }
func (p PairList) Less(i, j int) bool { return p[i].Key < p[j].Key }
func (p PairList) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
func sortData(data map[string]interface{}) PairList {
pl := make(PairList, len(data))
i := 0
for k, v := range data {
pl[i] = Pair{v, k}
i++
}
sort.Sort(pl)
return pl
}