github.com/dubbogo/gost@v1.14.0/sort/sort.go (about) 1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package gxsort 19 20 import ( 21 "sort" 22 ) 23 24 func Int64(slice []int64) { 25 sort.Sort(Int64Slice(slice)) 26 } 27 28 func Int32(slice []int32) { 29 sort.Sort(Int32Slice(slice)) 30 } 31 32 func Uint32(slice []uint32) { 33 sort.Sort(Uint32Slice(slice)) 34 } 35 36 type Int64Slice []int64 37 38 func (p Int64Slice) Len() int { 39 return len(p) 40 } 41 42 func (p Int64Slice) Less(i, j int) bool { 43 return p[i] < p[j] 44 } 45 46 func (p Int64Slice) Swap(i, j int) { 47 p[i], p[j] = p[j], p[i] 48 } 49 50 type Int32Slice []int32 51 52 func (p Int32Slice) Len() int { 53 return len(p) 54 } 55 56 func (p Int32Slice) Less(i, j int) bool { 57 return p[i] < p[j] 58 } 59 60 func (p Int32Slice) Swap(i, j int) { 61 p[i], p[j] = p[j], p[i] 62 } 63 64 type Uint32Slice []uint32 65 66 func (p Uint32Slice) Len() int { 67 return len(p) 68 } 69 70 func (p Uint32Slice) Less(i, j int) bool { 71 return p[i] < p[j] 72 } 73 74 func (p Uint32Slice) Swap(i, j int) { 75 p[i], p[j] = p[j], p[i] 76 }