data

package
v0.0.0-...-e5e7391 Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: BSD-3-Clause Imports: 2 Imported by: 0

README

Package data

This package provides basic utilities for working with data, e.g. sorting and other wrapper interfaces.

It also provides sub-packages for working with data structures, which integrate well with data itself.

  • list - for basic containers like stacks, queues, and sets

  • graph - for graph types

  • tree- for trees, like BST and heap

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LessFuncOrdered

func LessFuncOrdered[T constraints.Ordered](ordering SortOrder) func(T, T) bool

LessFuncOrdered selects the appropriate comparison function to check if the elements are ordered. If the returned function returns true, then the elements are sorted according to its |ordering|

func MaxValuer

func MaxValuer[T constraints.Ordered](values []Getter[T]) T

func MergeSort

func MergeSort[T constraints.Ordered](arr []T, ordering SortOrder) []T

func MergeSortCmp

func MergeSortCmp[T CmpOrdered[T]](arr []T, ordering SortOrder) []T

func MergeSortedArrays

func MergeSortedArrays[T any](
	a []T,
	b []T,
	lessFunc func(a T, b T) bool,
) []T

func MinValuer

func MinValuer[T constraints.Ordered](values []Getter[T]) T

func QuickSort

func QuickSort[T constraints.Ordered](arr []T, ordering SortOrder) []T

func QuickSortCmp

func QuickSortCmp[T CmpOrdered[T]](arr []T, ordering SortOrder) []T

func ToValues

func ToValues[T any](getters []Getter[T]) []T

Types

type CmpOrdered

type CmpOrdered[T any] interface {
	Cmp(T) int
}

CmpOrdered represents any type T with `Cmp(T) int` method. Examples of types that implement this interface include *big.Int and *big.Float.

type Getter

type Getter[T any] interface {
	GetValue() T
}

func FromValues

func FromValues[T any](values []T) []Getter[T]

func NewGetter

func NewGetter[T any](t T) Getter[T]

type LessFunc

type LessFunc[T any] func(list []T, i, j int) bool

func FactoryLessFuncCmp

func FactoryLessFuncCmp[T CmpOrdered[T]](
	order SortOrder,
) LessFunc[Getter[T]]

func FactoryLessFuncOrdered

func FactoryLessFuncOrdered[T constraints.Ordered](
	order SortOrder,
) LessFunc[Getter[T]]

Less implementation for constraints.Ordered

type Set

type Set[T comparable] interface {
	HasDuplicate(x T) bool
}

type Setter

type Setter[T any] interface {
	SetValue(T)
}

func NewSetter

func NewSetter[T any](t T) Setter[T]

type SortOrder

type SortOrder uint8
const (
	Ascending SortOrder = iota
	Descending
)

func (SortOrder) IsValid

func (d SortOrder) IsValid() bool

type Wrapper

type Wrapper[T any] interface {
	Setter[T]
	Getter[T]
}

func NewWrapper

func NewWrapper[T any](t T) Wrapper[T]

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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