algorithms

package
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: MIT Imports: 5 Imported by: 5 modules, 6 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BFS

func BFS[T comparable](initial T, neighbors func(T) ([]T, error), visit func(T) error) error

func Coinflip added in v0.0.4

func Coinflip(num, dem int) bool

Coinflip method

func DFS

func DFS[T comparable](initial T, neighbors func(T) ([]T, error), visit func(T) error) error

func Filter

func Filter[T any](arr []T, f func(T) bool) []T

func Index added in v0.0.3

func Index[T any](arr []T, f func(T) bool) int

func Int added in v0.0.4

func Int() int

Int returns a non-negative pseudo-random int.

func Intn added in v0.0.4

func Intn(max int) int

Intn generates an integer in range [0,max). By design this should panic if input is invalid, <= 0.

func IntnRange added in v0.0.4

func IntnRange(min, max int) int

IntnRange generates an integer in range [min,max). By design this should panic if input is invalid, <= 0.

func Map

func Map[T any, V any](arr []T, f func(T) V) []V

func MapKeys added in v0.1.9

func MapKeys[K comparable, V any](m map[K]V) []K

func MapValues added in v0.1.7

func MapValues[K comparable, V any](m map[K]V) []V

func Max added in v0.1.0

func Max[T Numeric](a, b T) T

func Merge added in v0.1.5

func Merge(maps ...map[string]interface{}) map[string]interface{}

func ProbeGraph

func ProbeGraph[T comparable](prober Prober[T], initial T, neighbors func(T) ([]T, error), visit func(T) error) error

func Reduce added in v0.0.5

func Reduce[T any, V any](arr []T, acc V, f func(T, V) V) V

func Retry added in v0.1.0

func Retry(op func() error, maxTries uint64) (err error)

func Reverse

func Reverse[T any](arr []T) []T

func String added in v0.0.4

func String(n int) string

String generates a random alphanumeric string, without vowels, which is n characters long. This will panic if n is less than zero.

func TopSort

func TopSort[T comparable](vals []T, neighbors func(T) ([]T, error)) ([]T, error)

func TopsortGraph added in v0.0.2

func TopsortGraph[T comparable](g containers.Graph[T]) ([]T, error)

Types

type FetchPageFunc added in v0.1.6

type FetchPageFunc[T any] func(page *string, size int64) ([]T, *PageInfo, error)

type Numeric added in v0.1.0

type Numeric interface {
	int | int8 | int16 | int32 | int64 | float64 | float32
}

type PageInfo added in v0.1.6

type PageInfo struct {
	HasNext  bool
	After    *string
	PageSize int64
}

type PageIter added in v0.1.6

type PageIter[T any] interface {
	NextPage() ([]T, error)
}

type Pager added in v0.1.6

type Pager[T any] struct {
	// contains filtered or unexported fields
}

func NewPager added in v0.1.6

func NewPager[T any](pageSize int64, fetchPage FetchPageFunc[T]) *Pager[T]

func (*Pager[T]) HasNext added in v0.1.6

func (p *Pager[T]) HasNext() bool

func (*Pager[T]) NextPage added in v0.1.6

func (p *Pager[T]) NextPage() ([]T, error)

type Prober

type Prober[T any] interface {
	Push(val T)
	Pop() (T, error)
	Empty() bool
}

Jump to

Keyboard shortcuts

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