Documentation
¶
Index ¶
- type Option
- type Queue
- func (q *Queue[E]) Clear()
- func (q *Queue[E]) Clone() *Queue[E]
- func (q *Queue[E]) Dequeue() (E, bool)
- func (q *Queue[E]) Enqueue(e E)
- func (q *Queue[E]) IsEmpty() bool
- func (q *Queue[E]) Len() int
- func (q *Queue[E]) MarshalJSON() ([]byte, error)
- func (q *Queue[E]) Peek() (E, bool)
- func (q *Queue[E]) String() string
- func (q *Queue[E]) UnmarshalJSON(data []byte) error
- func (q *Queue[E]) Values() []E
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
Option is a function type that can be used to configures properties of a priority queue..
func WithMaxPriority ¶
WithMaxPriority returns an Option that configures the priority queue to use max-heap ordering, where larger values have higher priority. By default, the queue uses min-heap ordering (smaller values have higher priority).
type Queue ¶
type Queue[E any] struct { // contains filtered or unexported fields }
Queue represents a priority queue. The queue is implemented by a binary heap.
func New ¶
New creates and returns a priority queue with the given comprarison function and options. The provided options can be used to configures the priority queue property. For example:
- WithSafe(): creates a thread-safe priority queue.
- WithMaxPriority(): creates a priority queue where higher value has higher priority.
By defaults, it creates a non-thread-safe priority queue use min-heap ordering. (smaller values have higher priority).
func (*Queue[E]) Dequeue ¶
Dequeue removes and returns the first element from the queue. Returns zero value of element and false if queue is empty.
func (*Queue[E]) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (*Queue[E]) Peek ¶
Peek returns first element of the queue without remove it. Returns zero value of element and false if queue is empty.
func (*Queue[E]) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.