Documentation
¶
Index ¶
- type PriorityItem
- type PriorityQueue
- func (pq *PriorityQueue[T]) Clear()
- func (pq *PriorityQueue[T]) Close()
- func (pq *PriorityQueue[T]) Len() int
- func (pq *PriorityQueue[T]) Peek() (value T, ok bool)
- func (pq *PriorityQueue[T]) Pop() (value T, ok bool)
- func (pq *PriorityQueue[T]) Push(value PriorityItem[T]) bool
- func (pq *PriorityQueue[T]) SearchFunc(fn func(T) bool) (T, bool)
- func (pq *PriorityQueue[T]) Shrink()
- func (pq *PriorityQueue[T]) WaitPop() (T, bool)
- func (pq *PriorityQueue[T]) WithRecycler(r recycler.Recycler) *PriorityQueue[T]
- type Queue
- func (q *Queue[T]) Clear()
- func (q *Queue[T]) Close()
- func (q *Queue[T]) DeleteFunc(fn func(T) bool) bool
- func (q *Queue[T]) IsEmpty() bool
- func (q *Queue[T]) Len() int
- func (q *Queue[T]) Peek() (T, bool)
- func (q *Queue[T]) Pop() (T, bool)
- func (q *Queue[T]) PopBatch(n int) ([]T, bool)
- func (q *Queue[T]) Push(data ...T) error
- func (q *Queue[T]) SearchFunc(fn func(T) bool) (T, bool)
- func (q *Queue[T]) Shrink()
- func (q *Queue[T]) WaitPop() (T, bool)
- func (q *Queue[T]) WithRecycler(r recycler.Recycler) *Queue[T]
- type Xchan
- type XchanConf
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PriorityItem ¶ added in v1.11.1
PriorityItem is an item with a priority. It is used to store items in the priority queue. Each item has a value of type T and an integer priority.
type PriorityQueue ¶ added in v1.11.1
type PriorityQueue[T any] struct { // contains filtered or unexported fields }
A PriorityQueue implements heap.Interface and holds Items. The zero value for PriorityQueue is an empty queue ready to use. PriorityQueue is a thread-safe priority queue that can hold elements of any type. It uses a mutex to ensure that only one goroutine can access the queue at a time.
func NewPriorityQueue ¶ added in v1.11.1
func (*PriorityQueue[T]) Clear ¶ added in v1.11.1
func (pq *PriorityQueue[T]) Clear()
Clear removes all elements from the priority queue.
func (*PriorityQueue[T]) Close ¶ added in v1.11.2
func (pq *PriorityQueue[T]) Close()
Close marks the priority queue as closed and wakes up all waiting goroutines.
func (*PriorityQueue[T]) Len ¶ added in v1.11.1
func (pq *PriorityQueue[T]) Len() int
Len returns the number of elements in the priority queue.
func (*PriorityQueue[T]) Peek ¶ added in v1.11.1
func (pq *PriorityQueue[T]) Peek() (value T, ok bool)
Peek returns the highest priority element without removing it from the queue. If the queue is empty, it returns the zero value of T and false.
func (*PriorityQueue[T]) Pop ¶ added in v1.11.1
func (pq *PriorityQueue[T]) Pop() (value T, ok bool)
Pop removes and returns the highest priority element from the priority queue. If the queue is empty, it returns the zero value of T and false.
func (*PriorityQueue[T]) Push ¶ added in v1.11.1
func (pq *PriorityQueue[T]) Push(value PriorityItem[T]) bool
Push adds an element to the priority queue with the given priority. Returns false if the queue is at max capacity.
func (*PriorityQueue[T]) SearchFunc ¶ added in v1.11.1
SearchFunc searches for an element in the priority queue that satisfies the given function. It returns the element and true if found, otherwise it returns the zero value of T and false.
func (*PriorityQueue[T]) Shrink ¶ added in v1.11.1
func (pq *PriorityQueue[T]) Shrink()
Shrink reduces the capacity of the priority queue's underlying slice to fit its length.
func (*PriorityQueue[T]) WaitPop ¶ added in v1.11.1
func (pq *PriorityQueue[T]) WaitPop() (T, bool)
WaitPop blocks until an element is available and returns it.
func (*PriorityQueue[T]) WithRecycler ¶ added in v1.11.1
type Queue ¶
type Queue[T any] struct { // contains filtered or unexported fields }
Generic queue type Queue is a thread-safe queue that can hold elements of any type. It uses a mutex to ensure that only one goroutine can access the queue at a time.
func (*Queue[T]) Clear ¶
func (q *Queue[T]) Clear()
Clear removes all elements from the queue. It locks the queue to ensure thread safety while clearing.
func (*Queue[T]) Close ¶ added in v1.10.4
func (q *Queue[T]) Close()
Close marks the queue as closed and wakes up all waiting goroutines.
func (*Queue[T]) DeleteFunc ¶
Delete removes the first occurrence of an element from the queue.
func (*Queue[T]) IsEmpty ¶
IsEmpty checks if the queue is empty. It locks the queue to ensure thread safety while checking.
func (*Queue[T]) Len ¶
Len returns the current length of the queue. It locks the queue to ensure thread safety while accessing the length.
func (*Queue[T]) Peek ¶
Peek returns the first element of the queue without removing it. It locks the queue to ensure thread safety while accessing the element. If the queue is empty, it returns a zero value of type T and false.
func (*Queue[T]) Pop ¶
Pop removes and returns the first element from the queue. It locks the queue to ensure thread safety while removing the element. If the queue is empty, it returns a zero value of type T and false.
func (*Queue[T]) PopBatch ¶
PopBatch removes and returns up to `n` elements from the queue. It locks the queue to ensure thread safety while removing the elements. If the queue has fewer than `n` elements, it returns all available elements.
func (*Queue[T]) Push ¶
Push adds one or more elements to the end of the queue. It locks the queue to ensure thread safety while adding elements. If the queue has a maximum capacity and is full, it returns an error. If the queue is not full, it appends the elements to the end of the queue. It returns nil if the operation is successful.
func (*Queue[T]) SearchFunc ¶
Search searches for an element in the queue using a custom function.
func (*Queue[T]) Shrink ¶ added in v1.9.6
func (q *Queue[T]) Shrink()
Shrink reduces the capacity of the queue to fit its current length. It locks the queue to ensure thread safety while shrinking.
type Xchan ¶ added in v1.8.1
type Xchan[T any] struct { // contains filtered or unexported fields }
Xchan is a concurrent channel that allows writing to an input channel and reading from an output channel. It uses a ring buffer to manage the flow of data between the input and output channels. It supports burst writes and ensures that the output channel is not blocked by full buffers. The buffer size is configurable, and it can handle concurrent writes and reads efficiently.
func (*Xchan[T]) BufferLen ¶ added in v1.8.1
BufferLen returns the number of elements in the buffer. It uses atomic operations to ensure thread safety when accessing the size.
func (*Xchan[T]) In ¶ added in v1.8.1
func (x *Xchan[T]) In() chan<- T
In returns the input channel for writing elements.