util

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2019 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Printer is global StdPrinter.
	Printer = &StdPrinter{Out: os.Stdout}
)

Functions

func ContainsString added in v0.3.0

func ContainsString(arr []string, value string) bool

ContainsString returns whether the value is in arr.

func Shuffle added in v0.3.0

func Shuffle(n int, swap func(int, int))

Shuffle pseudo-randomizes the order of elements. n is the number of elements. swap swaps the elements with indexes i and j. copy from rand.Shuffle of go1.10.

Types

type Queue added in v0.3.0

type Queue interface {
	// Put puts item into the queue and keeps blocking if the queue is full.
	// It will return immediately and do nothing if the item is nil.
	Put(item interface{})

	// PutTimeout puts item into the queue and waits for timeout if the queue is full.
	// If timeout <= 0, it will return false immediately when queue is full.
	// It will return immediately and do nothing if the item is nil.
	PutTimeout(item interface{}, timeout time.Duration) bool

	// Poll gets an item from the queue and keeps blocking if the queue is empty.
	Poll() interface{}

	// PollTimeout gets an item from the queue and waits for timeout if the queue is empty.
	// If timeout <= 0, it will return (nil, bool) immediately when queue is empty.
	PollTimeout(timeout time.Duration) (interface{}, bool)

	// Len returns the current size of the queue.
	Len() int
}

Queue blocking queue. The items putted into queue mustn't be nil.

func NewQueue added in v0.3.0

func NewQueue(capacity int) Queue

NewQueue creates a blocking queue. If capacity <= 0, the queue capacity is infinite.

type StdPrinter

type StdPrinter struct {
	Out io.Writer
}

StdPrinter output info to console directly.

func (*StdPrinter) Printf

func (sp *StdPrinter) Printf(format string, a ...interface{})

Printf formats according to a format specifier.

func (*StdPrinter) Println

func (sp *StdPrinter) Println(msg string)

Println output info to console directly.

Jump to

Keyboard shortcuts

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