Source File
sort.go
Belonging Package
golang.org/x/exp/slices
// Copyright 2022 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.package slicesimport ()// Sort sorts a slice of any ordered type in ascending order.// When sorting floating-point numbers, NaNs are ordered before other values.////go:fix inlinefunc [ ~[], cmp.Ordered]( ) {slices.Sort()}// SortFunc sorts the slice x in ascending order as determined by the cmp// function. This sort is not guaranteed to be stable.// cmp(a, b) should return a negative number when a < b, a positive number when// a > b and zero when a == b or when a is not comparable to b in the sense// of the formal definition of Strict Weak Ordering.//// SortFunc requires that cmp is a strict weak ordering.// See https://en.wikipedia.org/wiki/Weak_ordering#Strict_weak_orderings.// To indicate 'uncomparable', return 0 from the function.////go:fix inlinefunc [ ~[], any]( , func(, ) int) {slices.SortFunc(, )}// SortStableFunc sorts the slice x while keeping the original order of equal// elements, using cmp to compare elements in the same way as [SortFunc].////go:fix inlinefunc [ ~[], any]( , func(, ) int) {slices.SortStableFunc(, )}// IsSorted reports whether x is sorted in ascending order.////go:fix inlinefunc [ ~[], cmp.Ordered]( ) bool {return slices.IsSorted()}// IsSortedFunc reports whether x is sorted in ascending order, with cmp as the// comparison function as defined by [SortFunc].////go:fix inlinefunc [ ~[], any]( , func(, ) int) bool {return slices.IsSortedFunc(, )}// Min returns the minimal value in x. It panics if x is empty.// For floating-point numbers, Min propagates NaNs (any NaN value in x// forces the output to be NaN).////go:fix inlinefunc [ ~[], cmp.Ordered]( ) {return slices.Min()}// MinFunc returns the minimal value in x, using cmp to compare elements.// It panics if x is empty. If there is more than one minimal element// according to the cmp function, MinFunc returns the first one.////go:fix inlinefunc [ ~[], any]( , func(, ) int) {return slices.MinFunc(, )}// Max returns the maximal value in x. It panics if x is empty.// For floating-point E, Max propagates NaNs (any NaN value in x// forces the output to be NaN).////go:fix inlinefunc [ ~[], cmp.Ordered]( ) {return slices.Max()}// MaxFunc returns the maximal value in x, using cmp to compare elements.// It panics if x is empty. If there is more than one maximal element// according to the cmp function, MaxFunc returns the first one.////go:fix inlinefunc [ ~[], any]( , func(, ) int) {return slices.MaxFunc(, )}// BinarySearch searches for target in a sorted slice and returns the position// where target is found, or the position where target would appear in the// sort order; it also returns a bool saying whether the target is really found// in the slice. The slice must be sorted in increasing order.////go:fix inlinefunc [ ~[], cmp.Ordered]( , ) (int, bool) {return slices.BinarySearch(, )}// BinarySearchFunc works like [BinarySearch], but uses a custom comparison// function. The slice must be sorted in increasing order, where "increasing"// is defined by cmp. cmp should return 0 if the slice element matches// the target, a negative number if the slice element precedes the target,// or a positive number if the slice element follows the target.// cmp must implement the same ordering as the slice, such that if// cmp(a, t) < 0 and cmp(b, t) >= 0, then a must precede b in the slice.////go:fix inlinefunc [ ~[], , any]( , , func(, ) int) (int, bool) {return slices.BinarySearchFunc(, , )}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |