utils

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertPanics added in v0.1.2

func AssertPanics(t *testing.T, name string, f func())

func NormalizeDuration added in v0.0.4

func NormalizeDuration(d time.Duration) string

NormalizeDuration normalize duration

func UnsafeToBytes

func UnsafeToBytes(s string) []byte

func UnsafeToString

func UnsafeToString(b []byte) string

Types

type Copool

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

func NewCopool

func NewCopool(cap uint) *Copool

NewCopool return a goroutine pool with specified cap

func (*Copool) CtxGo

func (cp *Copool) CtxGo(ctx *context.Context, f func())

CtxGo executes f and accepts the context.

func (*Copool) Go

func (cp *Copool) Go(f func())

Go executes f.

func (*Copool) SetPanicHandler

func (cp *Copool) SetPanicHandler(f func(*context.Context, interface{})) *Copool

SetPanicHandler sets the panic handler.

type ObjectPool

type ObjectPool[T any] struct {
	// contains filtered or unexported fields
}

ObjectPool with Type

func NewObjectPool

func NewObjectPool[T any](creator func() T) *ObjectPool[T]

func (*ObjectPool[T]) Get

func (p *ObjectPool[T]) Get() T

func (*ObjectPool[T]) Put

func (p *ObjectPool[T]) Put(x T)

type PprofUtils added in v1.1.1

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

func NewPprofUtils added in v1.1.1

func NewPprofUtils(profile ProfileType, output string) *PprofUtils

func (*PprofUtils) StartProfile added in v1.1.1

func (p *PprofUtils) StartProfile()

func (*PprofUtils) StopProfile added in v1.1.1

func (p *PprofUtils) StopProfile()

type ProfileType added in v1.1.1

type ProfileType int
const (
	CPU ProfileType = iota
	HEAP
)

type Queue

type Queue[V any] struct {
	// contains filtered or unexported fields
}

Queue represents a single instance of the queue data structure.

func NewQueue

func NewQueue[V any](threadSafe bool) *Queue[V]

New constructs and returns a new Queue.

func (*Queue[V]) Get added in v0.1.1

func (q *Queue[V]) Get(i int) V

Get returns the element at index i in the queue. If the index is invalid, the call will panic. This method accepts both positive and negative index values. Index 0 refers to the first element, and index -1 refers to the last.

func (*Queue[V]) Len

func (q *Queue[V]) Len() int

Length returns the number of elements currently stored in the queue.

func (*Queue[V]) Pop added in v0.1.1

func (q *Queue[V]) Pop() V

Remove removes and returns the element from the front of the queue. If the queue is empty, the call will panic.

func (*Queue[V]) Put

func (q *Queue[V]) Put(elem V)

Add puts an element on the end of the queue.

func (*Queue[V]) Top added in v0.1.1

func (q *Queue[V]) Top() V

Top returns the element at the head of the queue. This call panics if the queue is empty.

func (*Queue[V]) TryPop added in v0.1.7

func (q *Queue[V]) TryPop() (V, bool)

Remove removes and returns the element from the front of the queue. If the queue is empty, the call will panic.

Jump to

Keyboard shortcuts

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