pool

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2024 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Callback

type Callback func(key, value any) bool

type IPool added in v0.2.2

type IPool interface {
	ForEach(cb Callback)
	Pool() *sync.Map
	Put(key, value any) *gerr.GatewayDError
	Get(key any) any
	GetOrPut(key, value any) (any, bool, *gerr.GatewayDError)
	Pop(key any) any
	Remove(key any)
	Size() int
	Clear()
	Cap() int
}

type Pool

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

func NewPool

func NewPool(ctx context.Context, capacity int) *Pool

NewPool creates a new pool with the given capacity.

func (*Pool) Cap added in v0.1.0

func (p *Pool) Cap() int

Cap returns the capacity of the pool.

func (*Pool) Clear

func (p *Pool) Clear()

Clear removes all key/value pairs from the pool.

func (*Pool) ForEach

func (p *Pool) ForEach(cb Callback)

ForEach iterates over the pool and calls the callback function for each key/value pair.

func (*Pool) Get

func (p *Pool) Get(key any) any

Get returns the value for the given key.

func (*Pool) GetOrPut

func (p *Pool) GetOrPut(key, value any) (any, bool, *gerr.GatewayDError)

GetOrPut returns the value for the given key if it exists, otherwise it adds the key/value pair to the pool.

func (*Pool) Pool

func (p *Pool) Pool() *sync.Map

Pool returns the underlying sync.Map.

func (*Pool) Pop

func (p *Pool) Pop(key any) any

Pop removes the key/value pair from the pool and returns the value.

func (*Pool) Put

func (p *Pool) Put(key, value any) *gerr.GatewayDError

Put adds a new key/value pair to the pool.

func (*Pool) Remove

func (p *Pool) Remove(key any)

Remove removes the key/value pair from the pool.

func (*Pool) Size

func (p *Pool) Size() int

Size returns the number of key/value pairs in the pool.

Jump to

Keyboard shortcuts

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