queue

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2025 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 Message

type Message[T any] struct {
	Priority int
	Value    T
}

Message encapsulates a value with its priority

type MessageHeap

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

MessageHeap implements the container/heap interface to hold messages

func NewMessageHeap

func NewMessageHeap[T any](size int) *MessageHeap[T]

NewMessageHeap returns an initialized MessageHeap of the specified size

func (*MessageHeap[T]) Len

func (h *MessageHeap[T]) Len() int

Len returns the length of the heap

func (*MessageHeap[T]) Less

func (h *MessageHeap[T]) Less(i, j int) bool

Less returns which item in the heap is smaller than the other

func (*MessageHeap[T]) Pop

func (h *MessageHeap[T]) Pop() any

Pop an item off the heap

func (*MessageHeap[T]) Push

func (h *MessageHeap[T]) Push(msg any)

Push an item onto the heap

func (*MessageHeap[T]) Swap

func (h *MessageHeap[T]) Swap(i, j int)

Swap two items in the heap

type PriorityQueue

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

PriorityQueue is like a channel but with dynamic buffering and returns items with the highest priority first

func NewPriorityQueue

func NewPriorityQueue[T any](queueSize int) *PriorityQueue[T]

NewPriorityQueue returns a PriorityQueue instance that is ready to send to

func (*PriorityQueue[T]) Recv

func (pq *PriorityQueue[T]) Recv(fn func(*Message[T]))

Recv takes a function that can receive messages sent to the queue

func (*PriorityQueue[T]) Send

func (pq *PriorityQueue[T]) Send(msg *Message[T])

Send puts items on the queue

Jump to

Keyboard shortcuts

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