algo

package module
v0.0.0-...-41bc7c6 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2024 License: MIT Imports: 1 Imported by: 0

README

algo

A collection of simple Go algorithms and containers inspired by the C++ Standard Libaray
  • vessels: generic containers including Deque, Stack and Queue
  • algorithms: generic algorithms including Map, Reduce and Filter
  • expected: testing helper functions

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clamp

func Clamp[T cmp.Ordered](v, lo, hi T) T

Return a result such that lo < v < hi

func ClampFunc

func ClampFunc[T any](v, lo, hi T, comp func(a, b T) bool) T

Return a result such that comp(lo, v) == true and comp(v, hi) == true

func Count

func Count[T comparable](s []T, value T) int

Return the count of value in s using ==

func CountFunc

func CountFunc[T any](s []T, f func(value T) bool) int

Return the number of times that f returns true for each of the elements of s

func Filter

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

Create and return a new slice containing only the elements of s for which f returns true.

func Map

func Map[T any, O any](s []T, f func(T) O) []O

Create and return a new slice filled with the results of applying function f on every element of s

func MapKeys

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

Create and return a new slice consisting of the keys of map m

func MapValues

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

Create and return a new slice consisting of the values of map m

func Merge

func Merge[T cmp.Ordered](a, b []T) []T

Create and return a slice consisting of the two sorted slices a and b. The result is also sorted. Elements are ordered using <

func MergeFunc

func MergeFunc[T any](a, b []T, comp func(x, y T) bool) []T

Create and return a slice consisting of the two sorted slices a and b. The result is also sorted. Elements are ordered using the function comp.

func Reduce

func Reduce[T any, O any](s []T, init O, f func(acc O, v T) O) O

Apply an accumulator function f to every element of s and return the final result. The accumulator is initialized with init, then with the result of subsequent iterations over s. The final result value returned from f is then returned from Reduce.

func Rotate

func Rotate[T any](s []T, middle int) []T

Create and return a new slice such that s[0, middle) is swapped with s[middle, len(s))

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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