utils

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2019 License: MIT Imports: 9 Imported by: 2

README

Utils

Build Status

Misc Go functions that didn't fit anywhere else :)

Documentation

Index

Constants

View Source
const Inf = int(MaxUint >> 1)

Inf = Plus Infinity

View Source
const MaxUint = ^uint(0)

MaxUint = Plus Infinity (unsigned)

View Source
const MinInf = -(Inf - 1)

MinInf = Minus Infinity

View Source
const MinUint = 0

MinUint = Minus Infinity (unsigned)

Variables

This section is empty.

Functions

func AbsInt

func AbsInt(a int) int

AbsInt returns the absolute value of an int

func ConstIntFunc

func ConstIntFunc(x int) func(int) int

ConstIntFunc returns a constant function

func IdentIntFunc

func IdentIntFunc(i int) int

IdentIntFunc returns the identity function

func IntsEq

func IntsEq(a, b []int) bool

IntsEq compares two []int (int slices) for equality

func IntsHas

func IntsHas(a []int, n int) bool

IntsHas checks if "a" ints slice has a value of "n".

func IntsSum

func IntsSum(a []int) (sum int)

IntsSum returns a sum of all ints in the slice.

func LoadFile

func LoadFile(fname string) (data string)

LoadFile loads a file and returns it as a string, handling reading errors internally

func LoadTwoStringsFromFile

func LoadTwoStringsFromFile(fname string) (string, string)

LoadTwoStringsFromFile loads the first two strings (separated by \n) from a file NOTE: Inefficient when you have (much) more than just two strings in a file.

func MaxInt

func MaxInt(ints ...int) (m int)

MaxInt returns the maximum int from multiple given ints

func MaxIntIndex

func MaxIntIndex(ints ...int) (i int)

MaxIntIndex returns the index corresponding to the maximum int

func MinInt

func MinInt(ints ...int) (m int)

MinInt returns the minimum int from multiple given ints

func MinIntIndex

func MinIntIndex(ints ...int) (i int)

MinIntIndex returns the index corresponding to the minimum int

func MultIntFunc

func MultIntFunc(x int) func(int) int

MultIntFunc returns a constant multiplier function

func NewInts

func NewInts(size int, opts ...int) (out []int)

NewInts returns a new []int, possibly initialized to some value (if given)

func ParseFloat

func ParseFloat(str string, opts ...int) (f float64)

ParseFloat converts a float from a string representation to an actual float

func ParseInt

func ParseInt(str string, opts ...int) (i int)

ParseInt converts an int from a string representation to an actual int

Types

type BitArray

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

func NewBitArray

func NewBitArray(size int) (ba *BitArray)

func (*BitArray) IsSet

func (ba *BitArray) IsSet(n int) bool

func (*BitArray) SetBit

func (ba *BitArray) SetBit(n int)

type FileHashes

type FileHashes map[string]string

FileHashes holds a map between file paths and their hashes

func FileHashesNew

func FileHashesNew(root string) (hashes FileHashes)

FileHashesNew walks all the folders/files starting at "root".

func (FileHashes) Diff

func (fh FileHashes) Diff(other FileHashes) (diff []string)

Diff computes the difference between two file hashes/maps.

func (FileHashes) Dump

func (fh FileHashes) Dump(fname string) (e error)

Dump writes file hashes to disk.

func (FileHashes) Filter

func (fh FileHashes) Filter(fnames []string) (out FileHashes)

Filter keeps only those FileHashes that are in fnames list.

func (FileHashes) Load

func (fh FileHashes) Load(fname string)

Load reads file hashes from disk.

func (FileHashes) Reject

func (fh FileHashes) Reject(fnames []string) (out FileHashes)

Reject returns all the FileHashes that are NOT in the fnames list.

Jump to

Keyboard shortcuts

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