Documentation
¶
Overview ¶
Package cmp provides tools to do equal, less, compare operations.
Index ¶
- func Bytes(a, b []byte) int
- func BytesEqual(a, b []byte) bool
- func Compare[T Ordered](x, y T) int
- func FCompare[T FOrdered](x, y T) int
- func FLess[T FOrdered](x, y T) bool
- func Less[T Ordered](a, b T) bool
- func Slice[E any](a, b []E, cmp func(ctx *Context[[]E], i int) int) int
- func SliceEx[E, T any](a, b []E, arg T, cmp func(arg T, ctx *Context[[]E], i int) int) int
- func String(a, b string) int
- func StringEqual(a, b string) bool
- type Context
- type FOrdered
- type Ordered
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BytesEqual ¶
BytesEqual reports whether a and b are the same length and contain the same bytes. A nil argument is equivalent to an empty slice.
func FCompare ¶
FCompare is Compare with floating-point types allowed.
Note:
- A NaN is considered less than any non-NaN
- A NaN is considered equal to a NaN
- and -0.0 is equal to 0.0.
func FLess ¶
FLess is Less with floating-point types.
Note:
- A NaN is considered less than any non-NaN
- -0.0 is not less than (is equal to) 0.0.
func Slice ¶
Compare compares the elements of a and b, using cmp on each pair of elements. The elements are compared sequentially, starting at index 0, until one element is not equal to the other.
The result of comparing the first non-matching elements is returned. If both slices are equal until one of them ends, the shorter slice is considered less than the longer one. The result is 0 if a == b, -1 if a < b, and +1 if a > b.
func StringEqual ¶
StringEqual reports whether a and b are the same length and contain the same bytes.
Types ¶
type FOrdered ¶
FOrdered is Ordered plus floating-point types.
Note that floating-point types may contain NaN ("not-a-number") values. An operator such as == or < will always report false when comparing a NaN value with any other value, NaN or not. See the FCompare function for a consistent way to compare NaN values.