queue

package module
v1.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2022 License: BSL-1.0 Imports: 0 Imported by: 0

README

queue

Go Reference Go Report Card

About

queue is a package for Go providing a simple First-In-First-Out queue. It is published on https://github.com/vbsw/golib/queue and https://gitlab.com/vbsw/golib/queue.

Copyright 2022, Vitali Baumtrok (vbsw@mailbox.org).

queue is distributed under the Boost Software License, version 1.0. (See accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)

queue is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Boost Software License for more details.

References

Documentation

Overview

Package queue provides a simple First-In-First-Out queue. Queue doesn't need to be initialized.

Index

Constants

View Source
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

func New(capacity int) *Queue

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

func (que *Queue) PutAllPrio(prio int, elements ...interface{})

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

func (que *Queue) PutPrio(prio int, element interface{})

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.

func (*Queue) Reset added in v1.1.0

func (que *Queue) Reset(capacity int)

Reset clears the queue and resets capacity. Negative capacity is ignored, but queue is still cleared.

func (*Queue) Size

func (que *Queue) Size() int

Size returns the number of elements in queue.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL