Documentation ¶
Overview ¶
Package utils provides common utility functions.
Provided functionalities: - sorting - comparators
Index ¶
- func ByteComparator(a, b interface{}) int
- func Float32Comparator(a, b interface{}) int
- func Float64Comparator(a, b interface{}) int
- func GenericComparator[T constraints.Ordered](a, b T) int
- func Int16Comparator(a, b interface{}) int
- func Int32Comparator(a, b interface{}) int
- func Int64Comparator(a, b interface{}) int
- func Int8Comparator(a, b interface{}) int
- func IntComparator(a, b interface{}) int
- func RuneComparator(a, b interface{}) int
- func Sort[T constraints.Ordered](values []T, comparator Comparator[T])
- func StringComparator(a, b interface{}) int
- func TimeComparator(a, b interface{}) int
- func ToString(value interface{}) string
- func UInt16Comparator(a, b interface{}) int
- func UInt32Comparator(a, b interface{}) int
- func UInt64Comparator(a, b interface{}) int
- func UInt8Comparator(a, b interface{}) int
- func UIntComparator(a, b interface{}) int
- type Comparator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ByteComparator ¶
func ByteComparator(a, b interface{}) int
ByteComparator provides a basic comparison on byte
func Float32Comparator ¶
func Float32Comparator(a, b interface{}) int
Float32Comparator provides a basic comparison on float32
func Float64Comparator ¶
func Float64Comparator(a, b interface{}) int
Float64Comparator provides a basic comparison on float64
func GenericComparator ¶
func GenericComparator[T constraints.Ordered](a, b T) int
func Int16Comparator ¶
func Int16Comparator(a, b interface{}) int
Int16Comparator provides a basic comparison on int16
func Int32Comparator ¶
func Int32Comparator(a, b interface{}) int
Int32Comparator provides a basic comparison on int32
func Int64Comparator ¶
func Int64Comparator(a, b interface{}) int
Int64Comparator provides a basic comparison on int64
func Int8Comparator ¶
func Int8Comparator(a, b interface{}) int
Int8Comparator provides a basic comparison on int8
func IntComparator ¶
func IntComparator(a, b interface{}) int
IntComparator provides a basic comparison on int
func RuneComparator ¶
func RuneComparator(a, b interface{}) int
RuneComparator provides a basic comparison on rune
func Sort ¶
func Sort[T constraints.Ordered](values []T, comparator Comparator[T])
Sort sorts values (in-place) with respect to the given comparator.
Uses Go's sort (hybrid of quicksort for large and then insertion sort for smaller slices).
func StringComparator ¶
func StringComparator(a, b interface{}) int
StringComparator provides a fast comparison on strings
func TimeComparator ¶
func TimeComparator(a, b interface{}) int
TimeComparator provides a basic comparison on time.Time
func UInt16Comparator ¶
func UInt16Comparator(a, b interface{}) int
UInt16Comparator provides a basic comparison on uint16
func UInt32Comparator ¶
func UInt32Comparator(a, b interface{}) int
UInt32Comparator provides a basic comparison on uint32
func UInt64Comparator ¶
func UInt64Comparator(a, b interface{}) int
UInt64Comparator provides a basic comparison on uint64
func UInt8Comparator ¶
func UInt8Comparator(a, b interface{}) int
UInt8Comparator provides a basic comparison on uint8
func UIntComparator ¶
func UIntComparator(a, b interface{}) int
UIntComparator provides a basic comparison on uint
Types ¶
type Comparator ¶
type Comparator[T constraints.Ordered] func(a, b T) int
Comparator will make type assertion (see IntComparator for example), which will panic if a or b are not of the asserted type.
Should return a number:
negative , if a < b zero , if a == b positive , if a > b