goutil

package module
v0.0.0-...-23b2599 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: MIT Imports: 5 Imported by: 0

README

goutil

Small Go utility functions.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abundant

func Abundant[K constraints.Integer](n K) bool

Abundant checks if n is an abundant integer. An integer is abundant if the sum of its proper divisors is more than the integer.

func All

func All[K comparable](vs []K, f func(K) bool) bool

All returns `true` if all of the Ks in the slice satisfy the predicate `f`.

func Any

func Any[K comparable](vs []K, f func(K) bool) bool

Any returns `true` if one of the Ks in the slice satisfies the predicate `f`.

func Deficient

func Deficient[K constraints.Integer](n K) bool

Deficient checks if n is a deficient integer. An integer is deficient if the sum of its proper divisors is less than the integer.

func Divisors

func Divisors[K constraints.Integer](n K) (divisors []K)

Divisors returns an integer slice of the proper divisors of n.

func EditDistance1

func EditDistance1(s, t string) int

EditDistance1 calculates the edit (or Levenschtein) distance between two strings by creating an entire backtraceable matrix.

func EditDistance2

func EditDistance2(s, t string) int

EditDistance2 calculates the edit (or Levenschtein) distance between two strings by just using the previous row and the previous values in the current row. This saves memory, but requires copying rows forward.

func Filter

func Filter[K comparable](vs []K, f func(K) bool) []K

Filter returns a new slice containing all Ks in the slice that satisfy the predicate `f`.

func HexStringToBase64String

func HexStringToBase64String(hexstring string) (string, error)

HexStringToBase64String converts a hexadecimal-encoded string to a base64-encoded string.

func HexToBase64

func HexToBase64(hexbytes []byte) ([]byte, error)

HexToBase64 converts a slice of hexadecimal bytes to the equivalent base64 slice of bytes.

func Include

func Include[K comparable](vs []K, t K) bool

Include returns `true` if the target string t is in the slice.

func Index

func Index[K comparable](vs []K, t K) int

Index returns the first index of the target string `t`, or -1 if no match is found.

func IsPalindrome

func IsPalindrome(s string) bool

IsPalindrome checks if s is a palindrome.

func IsPrime

func IsPrime[K constraints.Integer](n K) bool

IsPrime checks if n is prime.

func LevenschteinCost

func LevenschteinCost(m matrix, i, j, cost int) int

LevenschteinCost is used for best global alignment.

func Map

func Map[K comparable](vs []K, f func(K) K) []K

Map returns a new slice containing the results of applying the function `f` to each K in the original slice.

func Perfect

func Perfect[K constraints.Integer](n K) bool

Perfect checks if n is a perfect integer. An integer is perfect if the sum of its proper divisors is equal to the integer.

func PrimeSieve

func PrimeSieve[K constraints.Integer](max K) []K

PrimeSieve implements the Sieve of Eratosthenes.

func SmithWatermanCost

func SmithWatermanCost(m matrix, i, j, cost int) int

SmithWatermanCost is used for best local alignment.

func SqrtInt

func SqrtInt[K constraints.Integer](x K) K

SqrtInt determines the square root of an int.

func Sum

func Sum[K constraints.Integer](vals ...K) (sum K)

Sum returns the sum of vals.

func XORBytes

func XORBytes(a, b []byte) ([]byte, error)

XORBytes returns the result of XORing together a and b, byte by byte. It returns an error if a and b are not the same length.

Types

This section is empty.

Jump to

Keyboard shortcuts

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