github.com/intel/goresctrl@v0.5.0/pkg/utils/sort.go (about) 1 // Copyright 2020 Intel Corporation. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package utils 16 17 import ( 18 "sort" 19 ) 20 21 // SortUint64s sorts a slice of uint64 in increasing order. 22 func SortUint64s(a []uint64) { 23 sort.Sort(Uint64Slice(a)) 24 } 25 26 // Uint64Slice implmenents sort.Interface for a slice of uint64. 27 type Uint64Slice []uint64 28 29 // Len returns the length of an UintSlice 30 func (s Uint64Slice) Len() int { return len(s) } 31 32 // Less returns true if element at 'i' is less than the element at 'j' 33 func (s Uint64Slice) Less(i, j int) bool { return s[i] < s[j] } 34 35 // Swap swaps the values of two elements 36 func (s Uint64Slice) Swap(i, j int) { s[i], s[j] = s[j], s[i] }