utils

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2021 License: BSD-2-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(x int) int

Abs returns the absolute value of x.

func After

func After(value string, a string) string

After returns the substring from value which comes after a.

func AfterSpace

func AfterSpace(value string) string

AfterSpace returns the substring from value which comes after the first whitespace.

func Before

func Before(value string, a string) string

Before returns the substring from value which comes before a.

func BeforeSpace

func BeforeSpace(value string) string

BeforeSpace returns the substring from value which comes before the first whitespace.

func ContainsInt

func ContainsInt(lst []int, x int) bool

ContainsInt returns whether the list contains the x-element, or not.

func CountLines

func CountLines(filename string) (int, error)

CountLines efficiently counts the lines of text inside a file. See: https://stackoverflow.com/questions/24562942/golang-how-do-i-determine-the-number-of-lines-in-a-file-efficiently

func DeserializeFromFile

func DeserializeFromFile(filename string, obj interface{}) (err error)

DeserializeFromFile deserializes obj from file, using gob decoding.

func ForEachField

func ForEachField(i interface{}, callback func(field interface{}, name string, tag reflect.StructTag))

ForEachField calls the callback for each field of the struct i.

func GetNeighborsIndices

func GetNeighborsIndices(size, index, windowSize int) []int

GetNeighborsIndices returns the indices of the (circular) neighbours at position index.

func IntSliceEqual added in v0.5.0

func IntSliceEqual(a, b []int) bool

IntSliceEqual returns whether the two slices are equal, or not.

func IsStruct

func IsStruct(i interface{}) bool

IsStruct returns wether i is a struct.

func MakeIndices

func MakeIndices(size int) []int

MakeIndices returns a slice of the given size, where each element has the same value of its own index position.

func MakeIntMatrix

func MakeIntMatrix(rows, cols int) [][]int

MakeIntMatrix returns a new 2-dimensional slice of int.

func MinInt

func MinInt(a, b int) int

MinInt returns the minimum value between a and b.

func Name

func Name(i interface{}) string

Name returns the name of i.

func ReverseInPlace

func ReverseInPlace(s interface{})

ReverseInPlace reverses the elements of s (usually a slice).

func ReverseIntSlice

func ReverseIntSlice(lst []int) []int

ReverseIntSlice returns a reversed version of the given slice.

func ReverseString

func ReverseString(text string) string

ReverseString reverses the given string.

func SerializeToFile

func SerializeToFile(filename string, obj interface{}) (err error)

SerializeToFile serializes obj to file, using gob encoding.

func SplitByRune

func SplitByRune(str string) []string

SplitByRune splits the input string by runes, and produces a new slice of string, where each item is one rune converted to string.

func SumInt

func SumInt(v []int) (s int)

SumInt returns the sum of all values from v.

func TypeName

func TypeName(instance interface{}) string

TypeName returns the type name of instance.

Types

type Pool

type Pool struct {

	// New optionally specifies a function to generate
	// a value when Get would otherwise return nil.
	New func() interface{}
	// contains filtered or unexported fields
}

Pool is a naive implementation of a pool, based on broadcast channel. You can use this pool in the same way you use sync.Pool.

func NewPool

func NewPool(max int) *Pool

NewPool returns a new pool ready to use. The pool can contain up to a max number of items. Set the property New to generate new items when needed during the Get.

func (*Pool) Get

func (p *Pool) Get() interface{}

Get selects an item from the Pool, removes it from the Pool, and returns it to the caller. If the poll is empty, Get returns the result of calling p.New.

func (*Pool) Put

func (p *Pool) Put(x interface{})

Put adds x to the pool.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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