Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PriorityQueue ¶
type PriorityQueue[T any] struct { // contains filtered or unexported fields }
func NewPriorityQueue ¶
func NewPriorityQueue[T constraints.Ordered](t PriorityType) *PriorityQueue[T]
NewPriorityQueue returns a new PriorityQueue.
t is the type of priority queue : greater or lower
func NewPriorityQueueWithCompare ¶
func NewPriorityQueueWithCompare[T any](f compareFunc[T]) *PriorityQueue[T]
NewPriorityQueueWithCompare returns a new PriorityQueue.
f is Custom comparison function
compareFunc[T] func(src, des T) bool
when src has a higher priority than des, returns true
func (*PriorityQueue[T]) IsEmpty ¶
func (q *PriorityQueue[T]) IsEmpty() bool
IsEmpty returns true if the stack is empty.
func (*PriorityQueue[T]) Pop ¶
func (q *PriorityQueue[T]) Pop() (T, bool)
Pop removes the element with the highest priority from the priority queue and returns it. If the priority queue is empty, Pop returns the zero value of the type T and false.
func (*PriorityQueue[T]) Push ¶
func (q *PriorityQueue[T]) Push(e T)
Push adds an element to the priority queue.
func (*PriorityQueue[T]) Size ¶
func (q *PriorityQueue[T]) Size() int
Size returns the number of items in the stack.
func (*PriorityQueue[T]) Top ¶
func (q *PriorityQueue[T]) Top() (T, bool)
Top returns the element with the highest priority from the priority queue without removing it. If the priority queue is empty, Top returns the zero value of the type T and false.
type PriorityType ¶
type PriorityType int
const ( PriorityTypeGreater PriorityType PriorityTypeLower )