• Brad Fitzpatrick's avatar
    sort: add Slice, SliceStable, and SliceIsSorted · 22a2bdfe
    Brad Fitzpatrick authored
    Add helpers for sorting slices.
    
    Slice sorts slices:
    
        sort.Slice(s, func(i, j int) bool {
            if s[i].Foo != s[j].Foo {
                return s[i].Foo < s[j].Foo
            }
            return s[i].Bar < s[j].Bar
        })
    
    SliceStable is the same, but does a stable sort.
    
    SliceIsSorted reports whether a slice is already sorted.
    
    Fixes #16721
    
    Change-Id: I346530af1c5dee148ea9be85946fe08f23ae53e7
    Reviewed-on: https://go-review.googlesource.com/27321
    Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
    22a2bdfe
zfuncversion.go 4.78 KB