utils

package module
v0.0.0-...-3fd3bf7 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2022 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LangSuf = []string{
	".cpp98.cpp",
	".cpp11.cpp",
	".cpp14.cpp",
	".cpp17.cpp",
	".cpp20.cpp",
	".py2.py",
	".py3.py",
	".go",
	".java",
	".c",
	".txt",
	".py",
}

Functions

func ArrangeById

func ArrangeById[T any](id []int, val []T, getId func(*T) int) []T

every entry of val has an id, we will arrange val such that the result matches the given id array

func AtoiDefault

func AtoiDefault(str string, def int) int

func CopyFile

func CopyFile(src, dst string) (int64, error)

func DeepCopy

func DeepCopy(dst, src any) error

func DeleteSlice

func DeleteSlice[T any](a []T, id int)

func FileExists

func FileExists(filename string) bool

func FindIndex

func FindIndex[T comparable](array []T, v T) int

index of the first element equaling to v, otherwise return -1

func GetTempDir

func GetTempDir() (string, error)

func HasElement

func HasElement[T comparable](arr []T, val T) bool

func HasInt

func HasInt(srt []int, val int) bool

use binary search

func If

func If[T any](a bool, b T, c T) T

func JoinArray

func JoinArray[T any](val []T) string

func Map

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

func Max

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

func Min

func Min[T Numbers](a, b T) T

func RandomString

func RandomString(n int) string

func ResortEntry

func ResortEntry[T any](a []T, f func(int, int) bool, id int)

resort an sorted array after one entry has modified

func Reverse

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

func SHA256

func SHA256(str string) string

func StartsWith

func StartsWith(a, b string) bool

Whether a is start with b

func TimeStamp

func TimeStamp() int64

func TopoSort

func TopoSort(size int, dependon func(i, j int) bool) (res []int, err error)

dependon: whether i dependon j. Complexity: O(n^2)

func UnzipMemory

func UnzipMemory(mem []byte) (map[string][]byte, error)

Types

type ByteValue

type ByteValue int64

func (ByteValue) String

func (r ByteValue) String() string

type Checksum

type Checksum [32]byte

comparable

func FileChecksum

func FileChecksum(name string) Checksum

SHA256 hash for file content. for any error, return empty hash

func ReaderChecksum

func ReaderChecksum(reader io.Reader) Checksum

func (Checksum) String

func (r Checksum) String() string

type CtntType

type CtntType int
const (
	Cplain CtntType = iota
	Cbinary
	Csource
	Ccompconf
)

type HashValue

type HashValue []byte

func HashSum

func HashSum(a []HashValue) (sum HashValue)

type LangTag

type LangTag int
const (
	Lcpp LangTag = iota
	Lcpp11
	Lcpp14
	Lcpp17
	Lcpp20
	Lpython2
	Lpython3
	Lgo
	Ljava
	Lc
	Lplain
	Lpython
)

func SourceLang

func SourceLang(s string) LangTag

根据字符串推断程序语言

type Numbers

type Numbers interface {
	int | int8 | int16 | int32 | int64 | float32 | float64 | uint | uint8 | uint16 | uint32 | uint64
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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