Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConcurrentPriorityQueue ¶
type ConcurrentPriorityQueue[T any] struct { // contains filtered or unexported fields }
ConcurrentPriorityQueue is a thread-safe priority queue that provides a channel-based notification mechanism when items are inserted. All methods are safe for concurrent access.
func NewConcurrentPriorityQueue ¶
func NewConcurrentPriorityQueue[T any](smallerValuesFirst bool) *ConcurrentPriorityQueue[T]
NewConcurrentPriorityQueue creates a new instance of ConcurrentPriorityQueue. If smallerValuesFirst is true, inverts the priority so items with lower values take precedence.
func (*ConcurrentPriorityQueue[T]) Channel ¶
func (mq *ConcurrentPriorityQueue[T]) Channel() <-chan struct{}
Channel returns a signal channel that receives a signal when an item is inserted. This allows consumers to be notified of new items without polling.
func (*ConcurrentPriorityQueue[T]) Len ¶
func (mq *ConcurrentPriorityQueue[T]) Len() int
Len returns the number of items currently in the queue.
func (*ConcurrentPriorityQueue[T]) Pop ¶
func (mq *ConcurrentPriorityQueue[T]) Pop() (T, bool)
Pop removes and immediately returns the highest priority item from the queue. If the queue is empty, false is returned. If multiple items have the same priority, the oldest one by insertion time is returned.
func (*ConcurrentPriorityQueue[T]) Push ¶
func (mq *ConcurrentPriorityQueue[T]) Push(item T, priority uint64)
Push adds a new item to the queue with the specified priority. A notification is sent on the channel if it's not already full.
type PriorityQueue ¶
type PriorityQueue[T any] []*PriorityQueueItem[T]
PriorityQueue implements heap.Interface and holds PriorityQueueItems. It provides a priority queue where items with larger priority values are dequeued first. For items with equal priority, the oldest item (by insertion time) is dequeued first. CAUTION: not concurrency safe! Caller must implement their own synchronization.
func (PriorityQueue[T]) Len ¶
func (pq PriorityQueue[T]) Len() int
Len returns the number of items in the priority queue. CAUTION: not concurrency safe!
func (PriorityQueue[T]) Less ¶
func (pq PriorityQueue[T]) Less(i, j int) bool
Less determines the ordering of items in the priority queue. PriorityQueueItems with larger priority values come first. For items with equal priority, the oldest item (by insertion timestamp) comes first. Returns true if and only if item at index i should come before item at index j. CAUTION: not concurrency safe!
func (*PriorityQueue[T]) Pop ¶
func (pq *PriorityQueue[T]) Pop() any
Pop removes and returns the highest priority item from the queue. The returned item will have the highest priority value, or if multiple items have the same priority, the oldest one by insertion time. CAUTION: not concurrency safe!
func (*PriorityQueue[T]) Push ¶
func (pq *PriorityQueue[T]) Push(x any)
Push adds an item to the priority queue. The item's index is automatically set to its position in the heap. The item must be of type `*PriorityQueueItem[T]` otherwise the method will panic. CAUTION: not concurrency safe!
func (PriorityQueue[T]) Swap ¶
func (pq PriorityQueue[T]) Swap(i, j int)
Swap exchanges the items at the given indices and updates their heap indices. CAUTION: not concurrency safe!
type PriorityQueueItem ¶
type PriorityQueueItem[T any] struct { // contains filtered or unexported fields }
PriorityQueueItem is a generic item in the priority queue. Each item contains a message, priority value, and metadata for queue management. PriorityQueueItems are immutable once created and safe for concurrent access.
func NewPriorityQueueItem ¶
func NewPriorityQueueItem[T any](message T, priority uint64) *PriorityQueueItem[T]
NewPriorityQueueItem creates a new PriorityQueueItem with the given message and priority.
func (*PriorityQueueItem[T]) Message ¶
func (item *PriorityQueueItem[T]) Message() T
Message returns the message stored in the item.