pool

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 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 interface{}) bool

type IPool added in v0.2.2

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

type Pool

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

func NewPool

func NewPool(ctx context.Context, cap 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 interface{}) interface{}

Get returns the value for the given key.

func (*Pool) GetOrPut

func (p *Pool) GetOrPut(key, value interface{}) (interface{}, 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 interface{}) interface{}

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

func (*Pool) Put

func (p *Pool) Put(key, value interface{}) *gerr.GatewayDError

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

func (*Pool) Remove

func (p *Pool) Remove(key interface{})

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