github.com/gogo/protobuf@v1.3.2/sortkeys/sortkeys.go (about)

     1  // Protocol Buffers for Go with Gadgets
     2  //
     3  // Copyright (c) 2013, The GoGo Authors. All rights reserved.
     4  // http://github.com/gogo/protobuf
     5  //
     6  // Redistribution and use in source and binary forms, with or without
     7  // modification, are permitted provided that the following conditions are
     8  // met:
     9  //
    10  //     * Redistributions of source code must retain the above copyright
    11  // notice, this list of conditions and the following disclaimer.
    12  //     * Redistributions in binary form must reproduce the above
    13  // copyright notice, this list of conditions and the following disclaimer
    14  // in the documentation and/or other materials provided with the
    15  // distribution.
    16  //
    17  // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    18  // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    19  // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    20  // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    21  // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    22  // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    23  // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    24  // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    25  // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    26  // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    27  // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    28  
    29  package sortkeys
    30  
    31  import (
    32  	"sort"
    33  )
    34  
    35  func Strings(l []string) {
    36  	sort.Strings(l)
    37  }
    38  
    39  func Float64s(l []float64) {
    40  	sort.Float64s(l)
    41  }
    42  
    43  func Float32s(l []float32) {
    44  	sort.Sort(Float32Slice(l))
    45  }
    46  
    47  func Int64s(l []int64) {
    48  	sort.Sort(Int64Slice(l))
    49  }
    50  
    51  func Int32s(l []int32) {
    52  	sort.Sort(Int32Slice(l))
    53  }
    54  
    55  func Uint64s(l []uint64) {
    56  	sort.Sort(Uint64Slice(l))
    57  }
    58  
    59  func Uint32s(l []uint32) {
    60  	sort.Sort(Uint32Slice(l))
    61  }
    62  
    63  func Bools(l []bool) {
    64  	sort.Sort(BoolSlice(l))
    65  }
    66  
    67  type BoolSlice []bool
    68  
    69  func (p BoolSlice) Len() int           { return len(p) }
    70  func (p BoolSlice) Less(i, j int) bool { return p[j] }
    71  func (p BoolSlice) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }
    72  
    73  type Int64Slice []int64
    74  
    75  func (p Int64Slice) Len() int           { return len(p) }
    76  func (p Int64Slice) Less(i, j int) bool { return p[i] < p[j] }
    77  func (p Int64Slice) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }
    78  
    79  type Int32Slice []int32
    80  
    81  func (p Int32Slice) Len() int           { return len(p) }
    82  func (p Int32Slice) Less(i, j int) bool { return p[i] < p[j] }
    83  func (p Int32Slice) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }
    84  
    85  type Uint64Slice []uint64
    86  
    87  func (p Uint64Slice) Len() int           { return len(p) }
    88  func (p Uint64Slice) Less(i, j int) bool { return p[i] < p[j] }
    89  func (p Uint64Slice) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }
    90  
    91  type Uint32Slice []uint32
    92  
    93  func (p Uint32Slice) Len() int           { return len(p) }
    94  func (p Uint32Slice) Less(i, j int) bool { return p[i] < p[j] }
    95  func (p Uint32Slice) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }
    96  
    97  type Float32Slice []float32
    98  
    99  func (p Float32Slice) Len() int           { return len(p) }
   100  func (p Float32Slice) Less(i, j int) bool { return p[i] < p[j] }
   101  func (p Float32Slice) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }