xlib

package module
v0.0.0-...-94b9f60 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2020 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RedText start a red text output in fmt.Print
	RedText = "\x1b[1m\x1b[31m"
	// GreenText start a green text output in fmt.Print
	GreenText = "\x1b[1m\x1b[32m"
	// YellowText start a yellow text output in fmt.Print
	YellowText = "\x1b[1m\x1b[33m"
	// BlueText start a blue text output in fmt.Print
	BlueText = "\x1b[1m\x1b[34m"
	// MagentaText start a blue text output in fmt.Print
	MagentaText = "\x1b[1m\x1b[35m"
	// CyanText start a blue text output in fmt.Print
	CyanText = "\x1b[1m\x1b[36m"
	// ColorEnd end all color output in fmt.Print
	ColorEnd = "\x1b[0m"
)
View Source
const Version = "v0.1.0"

Version of xlib

Variables

This section is empty.

Functions

func Atof

func Atof(str string) float64

Atof coverts string to float type

func Atoi

func Atoi(str string) int

Atoi coverts string to int type

func CleanFilename

func CleanFilename(filename string) string

CleanFilename get rid of misc characters, only leave letter, number, '.' and '_'

func CloseFile

func CloseFile(file *os.File)

CloseFile close file and check errors

func CreateFile

func CreateFile(filename string) *os.File

CreateFile create file for write and check errors

func GetLogger

func GetLogger(programName string) *logging.Logger

GetLogger returns a Logger of go-logging package

func GetSortedKey

func GetSortedKey(m map[string]int, increase bool) []string

GetSortedKey do reversing of the string slice

func IsDir

func IsDir(dir string) bool

IsDir return true if is a dir

func Levenshtein

func Levenshtein(str1, str2 string, costIns, costRep, costDel int) int

Levenshtein calculate costIns: Defines the cost of insertion. costRep: Defines the cost of replacement. costDel: Defines the cost of deletion.

func Logger

func Logger(preMsg string, variable interface{})

Logger print the value of

func MaxInt

func MaxInt(a, b int) int

MaxInt return the max number

func MonteCarlo

func MonteCarlo(f func([]float64) float64, d Distribution, samples, dim int, ch chan<- float64)

MonteCarlo estimates the expected value of f under the distribution d using given number of samples. Note that f is of function type.

func OpenFile

func OpenFile(filename string) *os.File

OpenFile open file for read and check errors

func PadZero

func PadZero(number int, digitLength int, padChar string) (numberStr string)

PadZero pad strings with char to indicated length, like 1 -> 0001

func PageBreak

func PageBreak(msg ...interface{})

PageBreak print ---------- ss ------------

func ParallelMonteCarlo

func ParallelMonteCarlo(f func([]float64) float64, d Distribution, samples, dim int) float64

ParallelMonteCarlo are ..

func PrintVar

func PrintVar(debuging bool, varName string, varValue ...interface{})

PrintVar print variable with log package, when the debugging is turned on

func RandomDNA

func RandomDNA(length int) string

RandomDNA generate random DNA sequence

func RandomInt

func RandomInt(maximum int) int

RandomInt generate random Int

func RandomIntSlice

func RandomIntSlice(length int, minimum int, maximum int) []int

RandomIntSlice generate slice of random Int [minimum, maximum]

func RandomSentence

func RandomSentence(wordNum int) string

RandomSentence produce string of char of ascii 32 ~ 126

func RandomString

func RandomString(length int) string

RandomString produce string of char of ascii 32 ~ 126

func ReadCSVTable

func ReadCSVTable(file string, seperator string) map[string]string

ReadCSVTable read csv file int map[id:string]line:string

func ReadLines

func ReadLines(file string) []string

ReadLines read each line into a slice of string

func ReverseString

func ReverseString(s string) string

ReverseString do reversing of string

func ReverseStringSlice

func ReverseStringSlice(s []string)

ReverseStringSlice do reversing of string slice

func SimilarText

func SimilarText(first, second string, percent *float64) int

SimilarText find similarity

func WriteFile

func WriteFile(file *os.File, content string)

WriteFile and check errors

func WriteLines

func WriteLines(filename string, lines []string)

WriteLines write slice of string into file

Types

type Distribution

type Distribution interface {
	Rand() float64
}

Distribution interface define random number generation

type MapStringFloat

type MapStringFloat map[string]float64

MapStringFloat for sort map[string]int

func (*MapStringFloat) Sort

func (m *MapStringFloat) Sort(ascend bool) PairStringFloatSlice

Sort method of MapStringFloat

type MapStringInt

type MapStringInt map[string]int

MapStringInt for sort map[string]int

func (MapStringInt) Sort

func (m MapStringInt) Sort(ascend bool) PairStringIntSlice

Sort method of MapStringInt

type Normal

type Normal struct {
	Min float64
	Max float64
}

Normal is a type that generates normal random numbers with the given bounds

func (Normal) Rand

func (n Normal) Rand() float64

Rand is a method on Normal

type PairStringFloatSlice

type PairStringFloatSlice []pairStringFloat

PairStringFloatSlice is []struct{string,float64}

func (PairStringFloatSlice) Len

func (p PairStringFloatSlice) Len() int

func (PairStringFloatSlice) Less

func (p PairStringFloatSlice) Less(i, j int) bool

func (PairStringFloatSlice) Swap

func (p PairStringFloatSlice) Swap(i, j int)

type PairStringIntSlice

type PairStringIntSlice []pairStringInt

PairStringIntSlice is []struct{string, int}

func (PairStringIntSlice) Len

func (p PairStringIntSlice) Len() int

func (PairStringIntSlice) Less

func (p PairStringIntSlice) Less(i, j int) bool

func (PairStringIntSlice) Swap

func (p PairStringIntSlice) Swap(i, j int)

type Uniform

type Uniform struct {
	Min float64
	Max float64
}

Uniform is a type that generates uniform random numbers with the given bounds

func (Uniform) Rand

func (u Uniform) Rand() float64

Rand is a method on Uniform

Jump to

Keyboard shortcuts

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