comparer

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2025 License: MIT Imports: 0 Imported by: 0

README

comparer

As long as golang does not support overriding of comparation operators (as well as any other operators), this package designed to do it in available way.

It is required to determine order of elements in collection and can be used in BST and its descendants, aray sorting algos etc.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewStringComparer

func NewStringComparer() *stringComparer

Creates new comparer that works withs strings.

Types

type Comparer

type Comparer[T any] interface {
	// Returns
	// -1 if a > b
	// 0 if a = b
	// 1 if a < b
	Compare(a, b T) int
}

Comparer provides a way to compare 2 elements.

type ComparerFunc

type ComparerFunc[T any] func(a, b T) int

ComparerFunc lets create sateless comparer in short way.

func (ComparerFunc[T]) Compare

func (cf ComparerFunc[T]) Compare(a, b T) int

Jump to

Keyboard shortcuts

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