ordered

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: MPL-2.0 Imports: 0 Imported by: 2

Documentation

Overview

Package ordered contains ordered Pair and Triple types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ordered

type Ordered interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | ~float32 | ~float64 | ~string
}

Ordered is a constraint that permits any ordered type: any type that supports the operators < <= >= >.

type Pair

type Pair[T1, T2 Ordered] struct {
	F1 T1
	F2 T2
}

Pair is two element tuple of ordered values.

func MakePair

func MakePair[T1, T2 Ordered](v1 T1, v2 T2) Pair[T1, T2]

MakePair creates a new Pair.

func (Pair[T1, T2]) Compare

func (p Pair[T1, T2]) Compare(other Pair[T1, T2]) int

Compare returns an integer comparing two pairs in natural order. The result will be 0 if p == other, -1 if p < other, and +1 if p > other.

func (Pair[T1, T2]) Equal

func (p Pair[T1, T2]) Equal(other Pair[T1, T2]) bool

Equal checks if current pair is equal to the other.

func (Pair[T1, T2]) LessThan

func (p Pair[T1, T2]) LessThan(other Pair[T1, T2]) bool

LessThan checks if current pair is lesser than the other.

func (Pair[T1, T2]) MoreThan

func (p Pair[T1, T2]) MoreThan(other Pair[T1, T2]) bool

MoreThan checks if current pair is bigger than the other.

type Triple

type Triple[T1, T2, T3 Ordered] struct {
	V1 T1
	V2 T2
	V3 T3
}

Triple is three element tuple of ordered values.

func MakeTriple

func MakeTriple[T1, T2, T3 Ordered](v1 T1, v2 T2, v3 T3) Triple[T1, T2, T3]

MakeTriple creates a new Triple.

func (Triple[T1, T2, T3]) Compare

func (t Triple[T1, T2, T3]) Compare(other Triple[T1, T2, T3]) int

Compare returns an integer comparing two triples in natural order. The result will be 0 if t == other, -1 if t < other, and +1 if t > other.

func (Triple[T1, T2, T3]) Equal

func (t Triple[T1, T2, T3]) Equal(other Triple[T1, T2, T3]) bool

Equal checks if current triple is equal to the other.

func (Triple[T1, T2, T3]) LessThan

func (t Triple[T1, T2, T3]) LessThan(other Triple[T1, T2, T3]) bool

LessThan checks if current triple is lesser than the other.

func (Triple[T1, T2, T3]) MoreThan

func (t Triple[T1, T2, T3]) MoreThan(other Triple[T1, T2, T3]) bool

MoreThan checks if current triple is bigger than the other.

Jump to

Keyboard shortcuts

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