gods

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PoolChain

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

PoolChain is a dynamically-sized version of PoolDequeue.

This is implemented as a doubly-linked list queue of PoolDequeues where each dequeue is double the size of the previous one. Once a dequeue fills up, this allocates a new one and only ever pushes to the latest dequeue. Pops happen from the other end of the list and once a dequeue is exhausted, it gets removed from the list.

func NewPoolChain

func NewPoolChain() *PoolChain

NewPoolChain returns a new PoolChain.

func (*PoolChain) PopHead

func (c *PoolChain) PopHead() (any, bool)

popHead removes and returns the element at the head of the queue. It returns false if the queue is empty. It must only be called by a single producer.

func (*PoolChain) PopTail

func (c *PoolChain) PopTail() (any, bool)

PopTail removes and returns the element at the tail of the queue. It returns false if the queue is empty. It may be called by any number of consumers.

func (*PoolChain) PushHead

func (c *PoolChain) PushHead(val any) bool

PushHead adds val at the head of the queue. It returns false if the queue is full. It must only be called by a single producer.

type PoolDequeue

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

PoolDequeue is a lock-free fixed-size single-producer, multi-consumer queue. The single producer can both push and pop from the head, and consumers can pop from the tail.

It has the added feature that it nils out unused slots to avoid unnecessary retention of objects. This is important for sync.Pool, but not typically a property considered in the literature.

func NewPoolDequeue

func NewPoolDequeue(n int) *PoolDequeue

NewPoolDequeue returns a new PoolDequeue that can hold n elements.

func (*PoolDequeue) PopHead

func (d *PoolDequeue) PopHead() (any, bool)

PopHead removes and returns the element at the head of the queue. It returns false if the queue is empty. It must only be called by a single producer.

func (*PoolDequeue) PopTail

func (d *PoolDequeue) PopTail() (any, bool)

PopTail removes and returns the element at the tail of the queue. It returns false if the queue is empty. It may be called by any number of consumers.

func (*PoolDequeue) PushHead

func (d *PoolDequeue) PushHead(val any) bool

PushHead adds val at the head of the queue. It returns false if the queue is full. It must only be called by a single producer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳