transformer_utils

package
v0.4.41 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SpecialChars []rune
View Source
var SpecialCharsSet = map[rune]struct{}{
	'!': {}, '@': {}, '#': {}, '$': {}, '%': {}, '^': {}, '&': {}, '*': {}, '(': {}, ')': {},
	'-': {}, '+': {}, '=': {}, '_': {}, '[': {}, ']': {}, '{': {}, '}': {}, '|': {}, '\\': {},
	' ': {}, ';': {}, '"': {}, '<': {}, '>': {}, ',': {}, '.': {}, '/': {}, '?': {},
}

Functions

func AbsInt

func AbsInt[T int | int64 | int32 | uint | uint32 | uint64](n T) T

func AnyToFloat64

func AnyToFloat64(val any) (float64, error)

func Ceil

func Ceil[T int | int64 | int32 | uint | uint32 | uint64 | float32 | float64](n, ceiling T) T

If n is greater than ceiling, returns ceiling. Otherwise returns n.

func ClampInts

func ClampInts[T int | int32 | int64](input []T, minValue, maxValue *T) []T

func FindClosestPair

func FindClosestPair(sortedSlice1, sortedSlice2 []int64, maxValue int64) (leftidx, rightidx int64)

Given two sorted slices and a max value, returns the index from each slice that when summing their values, will be equal or as close to the maxValue as possible. There could be multiple combinations, but this algorithm attempts to find the closest pair, which finds the highest value in each slice that satisfies the maxValue constraint

func Floor

func Floor[T int | int64 | int32 | uint | uint32 | uint64](n, floor T) T

If n is less than floor, returns floor. Otherwise returns n.

func GenerateCryptoSeed

func GenerateCryptoSeed() (int64, error)

func GenerateRandomFloat64WithInclusiveBounds

func GenerateRandomFloat64WithInclusiveBounds(randomizer rng.Rand, minValue, maxValue float64) (float64, error)

Generates a random float64 in the range of the min and max float64 values

func GenerateRandomInt64FixedLength

func GenerateRandomInt64FixedLength(l int64) (int64, error)

Generates a random int64 of length l. For example, given a length of 4, possible values will always have a length of 4 digits.

func GenerateRandomInt64InLengthRange

func GenerateRandomInt64InLengthRange(minValue, maxValue int64) (int64, error)

Generates a random int64 with length in the inclusive range of [min, max]. For example, given a length range of [4, 7], possible values will have a length ranging from 4 -> 7 digits.

func GenerateRandomInt64InValueRange

func GenerateRandomInt64InValueRange(minValue, maxValue int64) (int64, error)

Generates a random int64 in the inclusive range of [min, max]. For example, given a range of [40, 50], possible values range from 40 -> 50, inclusive.

func GenerateRandomStringWithDefinedLength

func GenerateRandomStringWithDefinedLength(length int64) (string, error)

Generate a random alphanumeric string of length l

func GenerateRandomStringWithInclusiveBounds

func GenerateRandomStringWithInclusiveBounds(minValue, maxValue int64) (string, error)

Generate a random alphanumeric string within the interval [min, max]

func GenerateStringFromCorpus

func GenerateStringFromCorpus(
	randomizer rng.Rand,
	values []string,
	lengthMap map[int64][2]int,
	mapKeys []int64,
	minLength *int64,
	maxLength int64,
	exclusions []string,
) (string, error)

Generates a random string from the values corpus The lengthMap and mapKeys must be derivative of values. See the pre-generated values in the data-sets folder Eventually this will be abstracted into a Corpus struct for better readability. The expectation is the values, lengthMap, and mapKeys are all in their optimal, sorted form.

func GetInt64Length

func GetInt64Length(i int64) int64

gets the number of digits in an int64

func GetRandomCharacterString

func GetRandomCharacterString(randomizer rng.Rand, size int64) string

func GetRandomValueFromSlice

func GetRandomValueFromSlice[T any](arr []T) (T, error)

returns a random index from a one-dimensional slice

func GetSmallerOrEqualNumbers

func GetSmallerOrEqualNumbers(nums []int64, val int64) []int64

func IsAllowedSpecialChar

func IsAllowedSpecialChar(r rune) bool

func IsLastIntDigitZero

func IsLastIntDigitZero[T int | int64 | int32 | uint | uint32 | uint64](n T) bool

func IsNegativeInt

func IsNegativeInt[T int | int64 | int32 | uint | uint32 | uint64](val T) bool

func IsValidChar

func IsValidChar(s string) bool

use MaxASCII to ensure that the unicode value is only within the ASCII block which only contains latin numbers, letters and characters.

func IsValidDomain

func IsValidDomain(domain string) bool

func IsValidEmail

func IsValidEmail(email string) bool

func IsValidUsername

func IsValidUsername(username string) bool

func MaxInt

func MaxInt[T int | int64 | int32 | uint | uint32 | uint64](a, b T) T

func MinInt

func MinInt[T int | int64 | int32 | uint | uint32 | uint64](a, b T) T

func SetToSlice

func SetToSlice[T rune | string](input map[T]struct{}) []T

func SliceString

func SliceString(s string, l int) string

substrings a string using rune length to account for multi-byte characters

func StringInSlice

func StringInSlice(str string, list []string) bool

stringInSlice checks if a string is present in a slice of strings. It returns true if the string is found, and false otherwise.

func ToSet

func ToSet[T string | int64](input []T) map[T]struct{}

func TrimStringIfExceeds

func TrimStringIfExceeds(s string, maxLength int64) string

func WithoutCharacters

func WithoutCharacters(input string, invalidChars []rune) string

Types

This section is empty.

Jump to

Keyboard shortcuts

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