Documentation ¶
Overview ¶
Package gwutil provides general-purpose utilities that are not used by the core of gowid but that have proved useful for several pre-canned widgets.
Index ¶
- func AlmostEqual(a, b float64) bool
- func HamiltonAllocation(counts []int, alloc int) []int
- func IPow(a, b int) int
- func If(statement bool, a, b interface{}) interface{}
- func LStripByte(data []byte, s byte) []byte
- func LimitTo(a, v, b int) int
- func Map(vs []string, f func(string) string) []string
- func Max(i int, js ...int) int
- func Min(i int, js ...int) int
- func OptionString(opt IOption) string
- func ProfileHeap(filename string)
- func Round(f float64) float64
- func RoundFloatToInt(val float32) int
- func StartProfilingCPU(filename string)
- func StopProfilingCPU()
- func StringOfLength(r rune, n int) string
- func Sum(input ...int) int
- type IOption
- type Int64Option
- type IntOption
- type RuneOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AlmostEqual ¶
AlmostEqual returns true if its two arguments are within 1e-5 of each other.
func HamiltonAllocation ¶
HamiltonAllocation implements the Hamilton Method (Largest remainder method) to calculate integral ratios. (Like it is used in some elections.)
This is shamelessly cribbed from https://excess.org/svn/urwid/contrib/trunk/rbreu_scrollbar.py
counts -- list of integers ('votes per party') alloc -- total amount to be allocated ('total amount of seats')
func If ¶
func If(statement bool, a, b interface{}) interface{}
If is a convenience function for mimicking a ternary operator e.g. If(x<y, x, y).(int)
func LStripByte ¶
LStripByte returns a slice of its first argument which contains all bytes up to but not including its second argument.
func ProfileHeap ¶
func ProfileHeap(filename string)
ProfileHeap is a function I used when debugging and optimizing gowid. It writes a Go-heap-profile to the filename specified.
func Round ¶
Round returns a float64 representing the closest whole number to the supplied float64 argument.
func RoundFloatToInt ¶
RoundFloatToInt returns an int representing the closest int to the supplied float, rounding up or down.
func StartProfilingCPU ¶
func StartProfilingCPU(filename string)
StartProfilingCPU is a function I used when debugging and optimizing gowid. It starts the Go-profiler with output going to the specified file.
func StringOfLength ¶
StringOfLength returns a string consisting of n runes.
Types ¶
type Int64Option ¶
type Int64Option struct {
// contains filtered or unexported fields
}
Int64Option is intended to represent an Option[int]
func NoneInt64 ¶
func NoneInt64() Int64Option
func SomeInt64 ¶
func SomeInt64(x int64) Int64Option
func (Int64Option) IsNone ¶
func (i Int64Option) IsNone() bool
func (Int64Option) Val ¶
func (i Int64Option) Val() int64
func (Int64Option) Value ¶
func (i Int64Option) Value() interface{}
type IntOption ¶
type IntOption struct {
// contains filtered or unexported fields
}
IntOption is intended to represent an Option[int]
type RuneOption ¶
type RuneOption struct {
// contains filtered or unexported fields
}
RuneOption is intended to represent an Option[rune]
func NoneRune ¶
func NoneRune() RuneOption
func SomeRune ¶
func SomeRune(x rune) RuneOption
func (RuneOption) IsNone ¶
func (i RuneOption) IsNone() bool
func (RuneOption) String ¶
func (i RuneOption) String() string
func (RuneOption) Val ¶
func (i RuneOption) Val() rune
func (RuneOption) Value ¶
func (i RuneOption) Value() interface{}