]> Cypherpunks.ru repositories - gostls13.git/commit
sort: add Slice, SliceStable, and SliceIsSorted
authorBrad Fitzpatrick <bradfitz@golang.org>
Wed, 17 Aug 2016 14:29:00 +0000 (14:29 +0000)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 3 Oct 2016 16:09:56 +0000 (16:09 +0000)
commit22a2bdfedb95612984cec3141924953b88a607b7
tree580771c53123c7b484fec75d529d7266c7ef031f
parent003a598bf28ae8f77919c3bda2abb9d6d4f449bb
sort: add Slice, SliceStable, and SliceIsSorted

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: Russ Cox <rsc@golang.org>
src/cmd/dist/deps.go
src/go/build/deps_test.go
src/sort/genzfunc.go [new file with mode: 0644]
src/sort/sort.go
src/sort/sort_test.go
src/sort/zfuncversion.go [new file with mode: 0644]