cmp

package
v0.0.54 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 29, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package cmp can compare two numbers of any type. In addition, you can also compare two version using this package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareEQ

func CompareEQ(lhs, rhs any) bool

CompareEQ reports left hand side value whether equal right hand side value.

func CompareGE

func CompareGE(lhs, rhs any) bool

CompareGE reports left hand side value whether greater than or equal right hand side value.

func CompareGT

func CompareGT(lhs, rhs any) bool

CompareGT reports left hand side value whether greater than right hand side value.

func CompareLE

func CompareLE(lhs, rhs any) bool

CompareLE reports left hand side value whether less than or equal right hand side value.

func CompareLT

func CompareLT(lhs, rhs any) bool

CompareLT reports left hand side value whether less than right hand side value.

func Max added in v0.0.53

func Max[T cmp.Ordered](x, y T) T

Max compare two values and return larger value.

func Min added in v0.0.53

func Min[T cmp.Ordered](x, y T) T

Min compare two values and return smaller value.

func VerGEVer

func VerGEVer(v0, v1 string) (bool, error)

VerGEVer checks whether one version is greater than or equal to another version. Version like MAJOR.MINOR.PATCH, e.g. 2.1.1 > 2.1.0 > 2.0.0 > 1.0.0.

func VerGTVer

func VerGTVer(v0, v1 string) (bool, error)

VerGTVer checks whether one version is greater than another version. Version like MAJOR.MINOR.PATCH, e.g. 2.1.1 > 2.1.0 > 2.0.0 > 1.0.0.

func VerLEVer

func VerLEVer(v0, v1 string) (bool, error)

VerLEVer checks whether one version is less than or equal to another version. Version like MAJOR.MINOR.PATCH, e.g. 1.0.0 < 2.0.0 < 2.1.0 < 2.1.1.

func VerLTVer

func VerLTVer(v0, v1 string) (bool, error)

VerLTVer checks whether one version is less than another version. Version like MAJOR.MINOR.PATCH, e.g. 1.0.0 < 2.0.0 < 2.1.0 < 2.1.1.

Types

type CMPRSLT

type CMPRSLT int8
const (
	INCMP CMPRSLT = iota - 2
	LT
	EQ
	GT
)

func Cmp

func Cmp[T constraints.Ordered](lhs, rhs T) CMPRSLT

Cmp compares two numeric values or strings size.

func Compare

func Compare(lhs, rhs any) CMPRSLT

Compare compares two numeric values or strings size. The result is INCMP(incomparable), LT(less than), EQ(equal) or GT(greater than). Note that after Go 1.18, this function is deprecated, please use the function Cmp implemented by generics.

func VerCmp

func VerCmp(v0, v1, sep string) (CMPRSLT, error)

VerCmp compares two version using specified separator. Version like Field1.Field2.Field3,Field4..., e.g. 1.0.0.0 < 2.0.0.0 < 2.1.0.0 < 2.1.1.0.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL