Documentation
¶
Index ¶
- type CleanupMetrics
- type Entry
- type PriorityQueue
- func (pq *PriorityQueue[T]) Capacity() int
- func (pq *PriorityQueue[T]) Cleanup()
- func (pq *PriorityQueue[T]) Close()
- func (pq *PriorityQueue[T]) Elems() []T
- func (pq *PriorityQueue[T]) Empty() bool
- func (pq *PriorityQueue[T]) GetCleanupMetrics() CleanupMetrics
- func (pq *PriorityQueue[T]) Peek() (value T)
- func (pq *PriorityQueue[T]) Pop() (value T)
- func (pq *PriorityQueue[T]) Push(value T, priority int, ttl time.Duration)
- func (pq *PriorityQueue[T]) Remove(value T)
- func (pq *PriorityQueue[T]) Size() int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CleanupMetrics ¶
type CleanupMetrics struct {
AverageExpiredPerCleanup float64
TotalCleanupsPerformed int
ExpiredItemsInLastCleanup int
CurrentCleanupBatchSize int
CurrentPopLimit int
}
CleanupMetrics reports observed cleanup history and the queue's fixed cleanup/read-path policy.
type PriorityQueue ¶
type PriorityQueue[T comparable] struct { sync.RWMutex // contains filtered or unexported fields }
PriorityQueue is a priority queue that supports adding, removing, and updating elements with priorities.
func New ¶
func New[T comparable](capacity int, cleanupInterval time.Duration) *PriorityQueue[T]
New constructs a priority queue.
func (*PriorityQueue[T]) Capacity ¶
func (pq *PriorityQueue[T]) Capacity() int
Capacity returns the capacity of the queue.
func (*PriorityQueue[T]) Cleanup ¶
func (pq *PriorityQueue[T]) Cleanup()
Cleanup removes expired entries using the queue's fixed cleanup policy.
func (*PriorityQueue[T]) Close ¶
func (pq *PriorityQueue[T]) Close()
Close stops the cleanup goroutine.
func (*PriorityQueue[T]) Elems ¶
func (pq *PriorityQueue[T]) Elems() []T
Elems returns all elements in the queue sorted by priority from high to low.
func (*PriorityQueue[T]) Empty ¶
func (pq *PriorityQueue[T]) Empty() bool
Empty returns true if the queue is empty.
func (*PriorityQueue[T]) GetCleanupMetrics ¶
func (pq *PriorityQueue[T]) GetCleanupMetrics() CleanupMetrics
GetCleanupMetrics returns cleanup history and the current fixed policy.
func (*PriorityQueue[T]) Peek ¶
func (pq *PriorityQueue[T]) Peek() (value T)
Peek returns the highest priority entry without removing it.
func (*PriorityQueue[T]) Pop ¶
func (pq *PriorityQueue[T]) Pop() (value T)
Pop returns the highest priority entry and removes it from the queue.
func (*PriorityQueue[T]) Push ¶
func (pq *PriorityQueue[T]) Push(value T, priority int, ttl time.Duration)
Push adds a value to the queue with a priority and TTL.
func (*PriorityQueue[T]) Remove ¶
func (pq *PriorityQueue[T]) Remove(value T)
Remove removes a value from the queue.
func (*PriorityQueue[T]) Size ¶
func (pq *PriorityQueue[T]) Size() int
Size returns the number of elements in the queue.