Documentation
¶
Index ¶
- func ApplyOptions[T any](pq *PriorityQueue[T], opts ...Option[T])
- type Option
- type PriorityQueue
- func (pq *PriorityQueue[T]) Clear()
- func (pq *PriorityQueue[T]) Clone() *PriorityQueue[T]
- func (pq *PriorityQueue[T]) Contains(item T) bool
- func (pq *PriorityQueue[T]) ContainsFunc(fn func(T) bool) bool
- func (pq *PriorityQueue[T]) GetFunc(fn func(T) bool) T
- func (pq *PriorityQueue[T]) IsEmpty() bool
- func (pq *PriorityQueue[T]) Keys() []T
- func (pq *PriorityQueue[T]) Len() int
- func (pq *PriorityQueue[T]) LenFunc(fn func(T) bool) int
- func (pq *PriorityQueue[T]) MarshalJSON() ([]byte, error)
- func (pq *PriorityQueue[T]) Peek() (T, bool)
- func (pq *PriorityQueue[T]) Pop() (T, bool)
- func (pq *PriorityQueue[T]) PopFunc(fn func(T) bool) (T, bool)
- func (pq *PriorityQueue[T]) Push(item T)
- func (pq *PriorityQueue[T]) PushIfAbsent(item T) bool
- func (pq *PriorityQueue[T]) Remove(item T) bool
- func (pq *PriorityQueue[T]) RemoveFunc(fn func(T) bool) bool
- func (pq *PriorityQueue[T]) UnmarshalJSON(data []byte) error
- func (pq *PriorityQueue[T]) Vals() []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyOptions ¶
func ApplyOptions[T any](pq *PriorityQueue[T], opts ...Option[T])
Types ¶
type Option ¶
type Option[T any] func(*PriorityQueue[T])
Option is a function that configures a PriorityQueue.
func WithEquals ¶
WithEquals sets a custom equals function for the PriorityQueue.
type PriorityQueue ¶
type PriorityQueue[T any] struct { // contains filtered or unexported fields }
func New ¶
func New[T any](less func(a, b T) bool) *PriorityQueue[T]
New creates a new PriorityQueue with the provided comparison function.
func NewOrdered ¶
func NewOrdered[T cmp.Ordered]() *PriorityQueue[T]
NewOrdered creates a new PriorityQueue with Ordered elements.
func (*PriorityQueue[T]) Clear ¶
func (pq *PriorityQueue[T]) Clear()
Clear removes all items from the priority queue.
func (*PriorityQueue[T]) Clone ¶
func (pq *PriorityQueue[T]) Clone() *PriorityQueue[T]
func (*PriorityQueue[T]) Contains ¶
func (pq *PriorityQueue[T]) Contains(item T) bool
Contains checks if an item exists in the queue Note: This is an O(n) operation
func (*PriorityQueue[T]) ContainsFunc ¶
func (pq *PriorityQueue[T]) ContainsFunc(fn func(T) bool) bool
func (*PriorityQueue[T]) GetFunc ¶
func (pq *PriorityQueue[T]) GetFunc(fn func(T) bool) T
GetFunc returns the first item that satisfies the given function
func (*PriorityQueue[T]) IsEmpty ¶
func (pq *PriorityQueue[T]) IsEmpty() bool
IsEmpty checks if the priority queue is empty.
func (*PriorityQueue[T]) Keys ¶
func (pq *PriorityQueue[T]) Keys() []T
Keys returns a slice of all items in the queue, maintaining heap order
func (*PriorityQueue[T]) Len ¶
func (pq *PriorityQueue[T]) Len() int
Len returns the number of items in the priority queue.
func (*PriorityQueue[T]) LenFunc ¶
func (pq *PriorityQueue[T]) LenFunc(fn func(T) bool) int
LenFunc returns the number of items in the priority queue that satisfy the given function.
func (*PriorityQueue[T]) MarshalJSON ¶
func (pq *PriorityQueue[T]) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaller interface
func (*PriorityQueue[T]) Peek ¶
func (pq *PriorityQueue[T]) Peek() (T, bool)
Peek returns the highest priority item without removing it.
func (*PriorityQueue[T]) Pop ¶
func (pq *PriorityQueue[T]) Pop() (T, bool)
Pop removes and returns the highest priority item from the queue.
func (*PriorityQueue[T]) PopFunc ¶
func (pq *PriorityQueue[T]) PopFunc(fn func(T) bool) (T, bool)
PopFunc removes and returns the first item that satisfies the given function.
func (*PriorityQueue[T]) Push ¶
func (pq *PriorityQueue[T]) Push(item T)
Push adds an item to the priority queue.
func (*PriorityQueue[T]) PushIfAbsent ¶
func (pq *PriorityQueue[T]) PushIfAbsent(item T) bool
PushIfAbsent adds an item to the queue only if it's not already present Returns true if the item was added, false if it was already present
func (*PriorityQueue[T]) Remove ¶
func (pq *PriorityQueue[T]) Remove(item T) bool
Remove removes the first occurrence of the specified item from the queue Returns true if the item was found and removed, false otherwise
func (*PriorityQueue[T]) RemoveFunc ¶
func (pq *PriorityQueue[T]) RemoveFunc(fn func(T) bool) bool
RemoveFunc removes the first item that satisfies the given function
func (*PriorityQueue[T]) UnmarshalJSON ¶
func (pq *PriorityQueue[T]) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler interface
func (*PriorityQueue[T]) Vals ¶
func (pq *PriorityQueue[T]) Vals() []T
Vals is an alias for Keys() for compatibility