util

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2023 License: GPL-3.0 Imports: 1 Imported by: 5

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

Constants

View Source
const HexTable = "0123456789ABCDEF"

HexTable is a static string hex mapping constant string. This can be used multiple places to prevent reuse.

Variables

View Source
var Rand random

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() implementation 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!

func FastRandN

func FastRandN(n int) uint32

FastRandN is a fast thread local random function. This should be used in place instead of 'Rand.Uint32n()'.

This function will take a max value to specify.

func Itoa added in v0.5.0

func Itoa(v int64) string

Itoa converts val to a decimal string.

Similar to the "strconv" variant. Taken from the "internal/itoa" package.

func Uitoa added in v0.5.0

func Uitoa(v uint64) string

Uitoa converts val to a decimal string.

Similar to the "strconv" variant. Taken from the "internal/itoa" package.

func Uitoa16 added in v0.5.0

func Uitoa16(v uint64) string

Uitoa16 converts val to a hexadecimal string.

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

func (b *Builder) Cap() int

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

func (b *Builder) Grow(n int)

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

func (b *Builder) InsertByte(c byte) error

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

func (b *Builder) Len() int

Len returns the number of accumulated bytes; b.Len() == len(b.String()).

func (*Builder) Output added in v0.1.0

func (b *Builder) Output() string

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) String added in v0.1.0

func (b *Builder) String() string

String returns the accumulated string.

func (*Builder) Write added in v0.1.0

func (b *Builder) Write(p []byte) (int, error)

Write appends the contents of p to b's buffer.

Write always returns len(p), nil.

func (*Builder) WriteByte added in v0.1.0

func (b *Builder) WriteByte(c byte) error

WriteByte appends the byte c to b's buffer.

The returned error is always nil.

func (*Builder) WriteString added in v0.1.0

func (b *Builder) WriteString(s string) (int, error)

WriteString appends the contents of s to b's buffer.

It returns the length of s and a nil error.

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 crypt is a builtin package that provides compile-time encoded string values to be decoded and used when first starting up.
Package crypt is a builtin package that provides compile-time encoded string values to be decoded and used when first starting up.
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.

Jump to

Keyboard shortcuts

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