Documentation ¶
Overview ¶
Package util is a very generic package that is used to contain simple functions that may be used in multiple packages, such as the simple random number generator.
Generic re-implementations of built-in Golang structs or functions also sometimes land in here.
This package is affected by the "stdrand" build tag, which will replace the "fastrand" implementation with the "math/rand" random struct.
Index ¶
- Variables
- func FastRand() uint32
- func FastRandN(n int) uint32
- type Builder
- func (b *Builder) Cap() int
- func (b *Builder) Grow(n int)
- func (b *Builder) InsertByte(c byte) error
- func (b *Builder) Len() int
- func (b *Builder) Output() string
- func (b *Builder) Reset()
- func (b *Builder) String() string
- func (b *Builder) Write(p []byte) (int, error)
- func (b *Builder) WriteByte(c byte) error
- func (b *Builder) WriteString(s string) (int, error)
Constants ¶
This section is empty.
Variables ¶
var Rand = getRandom()
Rand is the custom Random number generator, based on the current time as a seed.
This struct is overridden by the tag "stdrand". By default, it will use the "unsafe" fastrand() implentation which is faster, but contains less entropy than the built-in, 'rand.Rand', which requires more memory and binary storage space.
Functions ¶
func FastRand ¶
func FastRand() uint32
FastRand is a fast thread local random function. This should be used in place instead of 'Rand.Uint32()'.
Taken from https://github.com/dgraph-io/ristretto/blob/master/z/rtutil.go Thanks!
Types ¶
type Builder ¶ added in v0.1.0
type Builder struct {
// contains filtered or unexported fields
}
A Builder is used to efficiently build a string using Write methods. It minimizes memory copying. The zero value is ready to use. Do not copy a non-zero Builder.
Re-implemented to remove UTF8 dependency and added some useful functions. Copy-check was also removed.
func (*Builder) Cap ¶ added in v0.1.0
Cap returns the capacity of the builder's underlying byte slice. It is the total space allocated for the string being built and includes any bytes already written.
func (*Builder) Grow ¶ added in v0.1.0
Grow grows b's capacity, if necessary, to guarantee space for another n bytes.
After Grow(n), at least n bytes can be written to b without another allocation. If n is negative, Grow is a NOP.
func (*Builder) InsertByte ¶ added in v0.1.0
InsertByte appends the byte c to b's buffer at the zero position.
The returned error is always nil.
func (*Builder) Len ¶ added in v0.1.0
Len returns the number of accumulated bytes; b.Len() == len(b.String()).
func (*Builder) Output ¶ added in v0.1.0
Output returns the accumulated string, then resets the value of this Builder.
func (*Builder) Reset ¶ added in v0.1.0
func (b *Builder) Reset()
Reset resets the Builder to be empty.
func (*Builder) Write ¶ added in v0.1.0
Write appends the contents of p to b's buffer.
Write always returns len(p), nil.
Directories ¶
Path | Synopsis |
---|---|
Package bugtrack enables the bug tracking system, which is comprised of a global logger that will write to Standard Error and on the filesystem in a temporary directory, "$TEMP" in *nix and "%TEMP%" on Windows, that is named "bugtrack-<PID>.log".
|
Package bugtrack enables the bug tracking system, which is comprised of a global logger that will write to Standard Error and on the filesystem in a temporary directory, "$TEMP" in *nix and "%TEMP%" on Windows, that is named "bugtrack-<PID>.log". |
Package text is a simple package for generating random string values with complex requirements and regular expressions.
|
Package text is a simple package for generating random string values with complex requirements and regular expressions. |
Package xerr is a simplistic (and more efficient) re-write of the "errors" built-in package.
|
Package xerr is a simplistic (and more efficient) re-write of the "errors" built-in package. |