util

package
v0.0.0-...-cf53f0f Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrPatternIsNull errorsx.SimpleError = "pattern cannot be null"
)

Variables

View Source
var (
	ErrUnsupportedPositionType errorsx.SimpleError = "type is not supported"
	ErrInsufficientSpace       errorsx.SimpleError = "buffer is to small to read a row, try increasing it"
)
View Source
var (
	IsNumber         = [256]uint8{'0': 1, '1': 1, '2': 1, '3': 1, '4': 1, '5': 1, '6': 1, '7': 1, '8': 1, '9': 1}
	IsLetter         = [256]uint8{'A': 1, 'B': 1, 'C': 1, 'D': 1, 'E': 1, 'F': 1, 'G': 1, 'H': 1, 'I': 1, 'J': 1, 'K': 1, 'L': 1, 'M': 1, 'N': 1, 'O': 1, 'P': 1, 'Q': 1, 'R': 1, 'S': 1, 'T': 1, 'U': 1, 'V': 1, 'W': 1, 'X': 1, 'Y': 1, 'Z': 1, 'a': 1, 'b': 1, 'c': 1, 'd': 1, 'e': 1, 'f': 1, 'g': 1, 'h': 1, 'i': 1, 'j': 1, 'k': 1, 'l': 1, 'm': 1, 'n': 1, 'o': 1, 'p': 1, 'q': 1, 'r': 1, 's': 1, 't': 1, 'u': 1, 'v': 1, 'w': 1, 'x': 1, 'y': 1, 'z': 1}
	IsUpperLetter    = [256]uint8{'A': 1, 'B': 1, 'C': 1, 'D': 1, 'E': 1, 'F': 1, 'G': 1, 'H': 1, 'I': 1, 'J': 1, 'K': 1, 'L': 1, 'M': 1, 'N': 1, 'O': 1, 'P': 1, 'Q': 1, 'R': 1, 'S': 1, 'T': 1, 'U': 1, 'V': 1, 'W': 1, 'X': 1, 'Y': 1, 'Z': 1}
	IsLowerLetter    = [256]uint8{'a': 1, 'b': 1, 'c': 1, 'd': 1, 'e': 1, 'f': 1, 'g': 1, 'h': 1, 'i': 1, 'j': 1, 'k': 1, 'l': 1, 'm': 1, 'n': 1, 'o': 1, 'p': 1, 'q': 1, 'r': 1, 's': 1, 't': 1, 'u': 1, 'v': 1, 'w': 1, 'x': 1, 'y': 1, 'z': 1}
	IsAlphaNumerical = [256]uint8{'0': 1, '1': 1, '2': 1, '3': 1, '4': 1, '5': 1, '6': 1, '7': 1, '8': 1, '9': 1, 'A': 1, 'B': 1, 'C': 1, 'D': 1, 'E': 1, 'F': 1, 'G': 1, 'H': 1, 'I': 1, 'J': 1, 'K': 1, 'L': 1, 'M': 1, 'N': 1, 'O': 1, 'P': 1, 'Q': 1, 'R': 1, 'S': 1, 'T': 1, 'U': 1, 'V': 1, 'W': 1, 'X': 1, 'Y': 1, 'Z': 1, 'a': 1, 'b': 1, 'c': 1, 'd': 1, 'e': 1, 'f': 1, 'g': 1, 'h': 1, 'i': 1, 'j': 1, 'k': 1, 'l': 1, 'm': 1, 'n': 1, 'o': 1, 'p': 1, 'q': 1, 'r': 1, 's': 1, 't': 1, 'u': 1, 'v': 1, 'w': 1, 'x': 1, 'y': 1, 'z': 1}
)
View Source
var AsciiSpace = [256]uint8{'\t': 1, '\n': 1, '\v': 1, '\f': 1, '\r': 1, ' ': 1}

Functions

func AppendRepeat

func AppendRepeat[S ~[]E, E any, I Integer](s S, n I, e E) []E

func AppendUnique

func AppendUnique[S ~[]E, E comparable](s S, e ...E) S

func AppendUniqueFunc

func AppendUniqueFunc[S ~[]E, E comparable](s S, cmp func(E) bool, e ...E) S

func BytesEqualString

func BytesEqualString(b []byte, s string) bool

func Combinate

func Combinate[E any](m int, items ...E) iter.Seq[[]E]

func CountDigits

func CountDigits(u uint64) uint64

func CountFunc

func CountFunc[S ~[]E, E any](s S, f func(E) bool) (res uint64)

func DoEachByteFile

func DoEachByteFile(filename string, tFunc TransformRowFunc) (err error)

func DoEachRowBuff

func DoEachRowBuff(r *bufio.Reader, f RowFunc, extra ...RowFunc) (err error)

func DoEachRowBuffN

func DoEachRowBuffN(r *bufio.Reader, n int, f MultiRowFunc, extra ...MultiRowFunc) (err error)

func DoEachRowFile

func DoEachRowFile(filename string, rowFunc RowFunc, extra ...RowFunc) (err error)

func DoEachRowFileN

func DoEachRowFileN(filename string, n int, rowFunc MultiRowFunc, extra ...MultiRowFunc) (err error)

func DoFile

func DoFile(filename string, execFunc ExecFunc, rowFunc RowFunc, extra ...RowFunc) (err error)

func DoFileN

func DoFileN(filename string, n int, execFunc MultiExecFunc, rowFunc MultiRowFunc, extra ...MultiRowFunc) (err error)

func FileExists

func FileExists(filePath string) (exists bool, err error)

func GetYearDay

func GetYearDay(args []string) (year string, days []string, err error)

func GetYearDays

func GetYearDays(args []string) (year string, days []string, err error)

func Identity

func Identity[T any](t T) T

func LenUnique

func LenUnique[S ~[]E, E comparable](s S) (res int)

func ParseInt

func ParseInt[T Signed](arr []byte) (res T)

func ParseInt64

func ParseInt64(arr []byte) (res int64, err error)

func ParseInt64ArrNoError

func ParseInt64ArrNoError(arr []byte) (res []int64)

func ParseInt64ArrNoErrorCache

func ParseInt64ArrNoErrorCache(arr []byte, input []int64) (res []int64)

func ParseInt64NoError

func ParseInt64NoError(arr []byte) (res int64)

func ParseIntArr

func ParseIntArr[T Signed](arr []byte) (res []T)

func ParseUint

func ParseUint[U Unsigned](arr []byte) (res U)

func ParseUint64ArrNoError

func ParseUint64ArrNoError(arr []byte) (res []uint64)

func ParseUint64NoError

func ParseUint64NoError(arr []byte) (res uint64)

func ParseUintArr

func ParseUintArr[U Unsigned](arr []byte) (res []U)

func PowerInt

func PowerInt(x, y int) int

func PowerInt64

func PowerInt64(x, y int64) int64

func PtrToUnsafeString

func PtrToUnsafeString(s *[]byte) string

func Repeat

func Repeat[I Integer, E any](n I, e E) []E

func Seq2ToChannel

func Seq2ToChannel[K comparable, V any](s iter.Seq2[K, V], buffer int) (*sync.WaitGroup, <-chan V)

func SeqToChannel

func SeqToChannel[V any](s iter.Seq[V], buffer int) (*sync.WaitGroup, <-chan V)

func SliceToChannel

func SliceToChannel[S ~[]V, V any](s S, buffer int) (*sync.WaitGroup, <-chan V)

func ToKeysSeq2

func ToKeysSeq2[S ~[]K, K comparable, V any](s S, v V) iter.Seq2[K, V]

func ToUnsafeString

func ToUnsafeString(s []byte) string

func Unique

func Unique[S ~[]E, E comparable](s S) (res S)

Types

type Coordinate

type Coordinate interface {
	uint8 | uint16 | uint32
}

type Coordinater

type Coordinater[C Coordinate] interface {
	Y() C
	X() C
}

type ExecFunc

type ExecFunc func(*bufio.Reader, RowFunc, ...RowFunc) error

type Integer

type Integer interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type MultiExecFunc

type MultiExecFunc func(*bufio.Reader, int, MultiRowFunc, ...MultiRowFunc) error

type MultiRowFunc

type MultiRowFunc func(row [][]byte, nr int) error

type PatternFunc

type PatternFunc func([]byte) bool

type Patterner

type Patterner interface {
	Pattern([]byte) bool
}

type Pos

type Pos[U UnsignedPos] interface {
	~uint16 | ~uint32 | ~uint64
	New(y, x int) U
	IsInside(U) bool
}

type PositionMap

type PositionMap[P Pos[U], U UnsignedPos, T any] struct {
	Map       []T
	Positions []U
	MaxPos    U
}

func ToMapOfPositions

func ToMapOfPositions[P Pos[U], U UnsignedPos, V any](filename string, transform func(byte) V, extra ...RowFunc) (posMap PositionMap[P, U, V], err error)

func ToMapOfPositionsByte

func ToMapOfPositionsByte[P Pos[U], U UnsignedPos](filename string, extra ...RowFunc) (posMap PositionMap[P, U, byte], err error)

func (PositionMap[P, E, T]) Contains

func (p PositionMap[P, E, T]) Contains(pos E) bool

func (PositionMap[P, E, T]) HasInside

func (p PositionMap[P, E, T]) HasInside(pos P) bool

func (PositionMap[P, E, T]) MapString

func (p PositionMap[P, E, T]) MapString() string

func (PositionMap[P, E, T]) String

func (p PositionMap[P, E, T]) String() string

type RowFunc

type RowFunc func(row []byte, nr int) error

type Signed

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type StringPattern

type StringPattern string

func (StringPattern) Pattern

func (s StringPattern) Pattern(p []byte) bool

type Tokenizer

type Tokenizer struct {
	// contains filtered or unexported fields
}

func NewTokenizer

func NewTokenizer(src []byte, p Patterner, patterns ...Patterner) (t *Tokenizer, err error)

type TransformRowFunc

type TransformRowFunc func(b byte)

type Unsigned

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type UnsignedPos

type UnsignedPos interface {
	~uint16 | ~uint32 | ~uint64
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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