Documentation
¶
Overview ¶
Package queue provides a simple First-In-First-Out queue. Queue doesn't need to be initialized.
Index ¶
- Constants
- type Queue
- func (que *Queue) All() []interface{}
- func (que *Queue) First() interface{}
- func (que *Queue) Put(element interface{})
- func (que *Queue) PutAll(elements ...interface{})
- func (que *Queue) PutAllPrio(prio int, elements ...interface{})
- func (que *Queue) PutPrio(prio int, element interface{})
- func (que *Queue) Reset(capacity int)
- func (que *Queue) Size() int
- type TypedElement
- type TypedQueue
- func (que *TypedQueue) All() []TypedElement
- func (que *TypedQueue) First() TypedElement
- func (que *TypedQueue) Put(element TypedElement)
- func (que *TypedQueue) PutAll(elements ...TypedElement)
- func (que *TypedQueue) PutAllPrio(prio int, elements ...TypedElement)
- func (que *TypedQueue) PutPrio(prio int, element TypedElement)
- func (que *TypedQueue) Reset(capacity int)
- func (que *TypedQueue) Size() int
Constants ¶
const ( PrioMin = int(^uint(0) >> 1) PrioMax = -PrioMin - 1 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue is a First-In-First-Out buffer.
func New ¶
New returns a new queue. If capacity is negative, capacity is set to zero and queue is initialized with capacity of 8 at first Put.
func (*Queue) All ¶
func (que *Queue) All() []interface{}
All removes all elements from queue and returns them.
func (*Queue) First ¶
func (que *Queue) First() interface{}
First removes first element from queue and returns it.
func (*Queue) Put ¶
func (que *Queue) Put(element interface{})
Put appends element at the end of the queue.
func (*Queue) PutAll ¶
func (que *Queue) PutAll(elements ...interface{})
PutAll appends elements at the end of the queue.
func (*Queue) PutAllPrio ¶
PutAllPrio inserts elements in queue. The position of inserted elements is determined by parameter prio. A low prio number means hight priority. Elements are put before other elements with lower priority, or after elements with same or higher priority.
func (*Queue) PutPrio ¶
PutPrio inserts element in queue. The position of inserted element is determined by parameter prio. A low prio number means hight priority. Element is put before other elements with lower priority, or after elements with same or higher priority.
type TypedElement ¶
type TypedElement interface {
OnQueuePut()
OnQueueRemove()
}
TypedElement is an interface to control elements by type.
type TypedQueue ¶
type TypedQueue struct {
// contains filtered or unexported fields
}
TypedQueue is a First-In-First-Out buffer for typed elements.
func NewTyped ¶
func NewTyped(capacity int) *TypedQueue
NewTyped returns a new typed queue. If capacity is negative, capacity is set to zero and queue is initialized with capacity of 8 at first Put.
func (*TypedQueue) All ¶
func (que *TypedQueue) All() []TypedElement
All removes all elements from queue and returns them. Function OnQueueRemove is called on every element after they have been removed from the queue.
func (*TypedQueue) First ¶
func (que *TypedQueue) First() TypedElement
First removes first element from queue and returns it. Function OnQueueRemove is called on element after it has been removed from the queue.
func (*TypedQueue) Put ¶
func (que *TypedQueue) Put(element TypedElement)
Put appends element at the end of the queue. Function OnQueuePut is called on element after it has been added to the queue.
func (*TypedQueue) PutAll ¶
func (que *TypedQueue) PutAll(elements ...TypedElement)
PutAll appends elements at the end of the queue. Function OnQueuePut is called on every element after they have been added to the queue.
func (*TypedQueue) PutAllPrio ¶
func (que *TypedQueue) PutAllPrio(prio int, elements ...TypedElement)
PutAllPrio inserts elements in queue. Function OnQueuePut is called on every element after they have been added to the queue. The position of inserted elements is determined by parameter prio. A low prio number means hight priority. Elements are put before other elements with lower priority, or after elements with same or higher priority.
func (*TypedQueue) PutPrio ¶
func (que *TypedQueue) PutPrio(prio int, element TypedElement)
PutPrio inserts element in queue. Function OnQueuePut is called on element after it has been added to the queue. The position of inserted element is determined by parameter prio. A low prio number means hight priority. Element is put before other elements with lower priority, or after elements with same or higher priority.
func (*TypedQueue) Reset ¶ added in v1.1.0
func (que *TypedQueue) Reset(capacity int)
Reset clears the queue and resets capacity. Negative capacity is ignored, but queue is still cleared.
func (*TypedQueue) Size ¶
func (que *TypedQueue) Size() int
Size returns the number of elements in queue.