Documentation
¶
Overview ¶
Package kyu provides implementations of queues data structures with various different characteristics.
Index ¶
- type Element
- type PDeque
- func (q *PDeque) Contains(e *Element) bool
- func (q *PDeque) Inverse() Queue
- func (q *PDeque) IsBack(e *Element) bool
- func (q *PDeque) IsFront(e *Element) bool
- func (q *PDeque) Len() int
- func (q *PDeque) Peek() (e *Element, ok bool)
- func (q *PDeque) PeekBack() (e *Element, ok bool)
- func (q *PDeque) Pop() (v interface{}, ok bool)
- func (q *PDeque) PopBack() (v interface{}, ok bool)
- func (q *PDeque) Push(v interface{}) *Element
- func (q *PDeque) Remove(e *Element)
- func (q *PDeque) Update(e *Element)
- type PQueue
- func (q *PQueue) Contains(e *Element) bool
- func (q *PQueue) IsFront(e *Element) bool
- func (q *PQueue) Len() int
- func (q *PQueue) Peek() (e *Element, ok bool)
- func (q *PQueue) Pop() (v interface{}, ok bool)
- func (q *PQueue) Push(v interface{}) *Element
- func (q *PQueue) Remove(e *Element)
- func (q *PQueue) Update(e *Element)
- type Queue
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Element ¶
type Element struct { // Value is the value associated with the element. Value interface{} // contains filtered or unexported fields }
Element is a container for a value on a queue.
It couple's the element's value with queue-specific meta-data that allows manipulation of the element while it is on the queue.
type PDeque ¶
type PDeque struct { // Less returns true if a should be closer to the front of the queue than b. Less func(a, b interface{}) bool // contains filtered or unexported fields }
PDeque is a double-ended priority queue.
It supports efficient inspection and removal of elements at both the front and back of the queue. The lowest elements appear towards the front of the queue.
func (*PDeque) Inverse ¶
Inverse returns an inverted "view" of q, such that q.Inverse().Pop() is equivalent to q.PopBack(), etc.
func (*PDeque) Peek ¶
Peek returns the element at the front of the queue without removing it from the queue.
If the queue is empty, e is nil and ok is false.
func (*PDeque) PeekBack ¶
PeekBack returns the element at the back of the queue without removing it from the queue.
If the queue is empty, e is nil and ok is false.
func (*PDeque) Pop ¶
Pop removes the element at the front of the queue and returns its value.
If the queue is empty, v is nil and ok is false.
func (*PDeque) PopBack ¶
PopBack removes the element at the back of the queue and returns its value.
If the queue is empty, v is nil and ok is false.
type PQueue ¶
type PQueue struct { // Less returns true if a should be closer to the front of the queue than b. Less func(a, b interface{}) bool // contains filtered or unexported fields }
PQueue is a priority queue.
It supports efficient inspection and removal of elements at the front of the queue. The lowest elements appear towards the front of the queue.
func (*PQueue) Peek ¶
Peek returns the element at the front of the queue without removing it from the queue.
If the queue is empty, e is nil and ok is false.
func (*PQueue) Pop ¶
Pop removes the element at the front of the queue and returns its value.
If the queue is empty, v is nil and ok is false.
type Queue ¶
type Queue interface { // Len returns the number of elements in the queue. Len() int // Push adds a new value to the queue. // // It returns the element that contains that value. Push(v interface{}) *Element // Peek returns the element at the front of the queue without removing it // from the queue. // // If the queue is empty, e is nil and ok is false. Peek() (e *Element, ok bool) // Pop removes the element at the front of the queue and returns its value. // // If the queue is empty, v is nil and ok is false. Pop() (v interface{}, ok bool) // Contains returns true if e is in the queue. Contains(e *Element) bool // IsFront returns true if e is at the front of the queue. IsFront(e *Element) bool // Update reorders the queue to reflect a change in e.Value that might cause // e to occupy a different position within in the queue. Update(e *Element) // Remove removes e from the queue. Remove(e *Element) }
Queue is an interface for a queue.
The interface makes the distinction between a "value", which is the user-provided value to be placed on the queue, and an "element", which represents a value that has been placed on a queue.