queue_dll_ts

package
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: BSD-3-Clause Imports: 2 Imported by: 0

README

= A generics based Go Queue.

A simple stack with Push, Pop, Length, IsEmpty using Go generics.

This requires version 1.18beta1 of Go to be compiled and used.

This queue implemenation is based on using a generic DLL and the
performance will be significantly different when poping
values thatn a queue based on a doublly linked list.  In this
implentation a copy of the queued dat ais made each time a
`Pop` occures.  This will result in an order(n) performance
for this operation.
A DLL based queue has a order(1) timing for the
same operation.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Queue

type Queue[T comparable.Equality] struct {
	// contains filtered or unexported fields
}

Queue is a generic type buildt on top of a generic DLL

func (*Queue[T]) Dequeue

func (ns *Queue[T]) Dequeue() (rv *T, err error)

Dequeue remove and return an element from the queue (if there is one), else return an error.

func (*Queue[T]) Enqueue

func (ns *Queue[T]) Enqueue(t *T)

Enqueue is the same as Push. Enqueue will push new data of type [T any] onto the queue.

func (*Queue[T]) IsEmpty

func (ns *Queue[T]) IsEmpty() bool

IsEmpty will return true if the queue is empty

func (*Queue[T]) Length

func (ns *Queue[T]) Length() int

Length returns the number of elements in the queue.

func (*Queue[T]) Peek

func (ns *Queue[T]) Peek() (*T, error)

Peek returns the top element of the queue or an error indicating that the queue is empty.

func (*Queue[T]) Pop

func (ns *Queue[T]) Pop() (err error)

Pop will remove the top element from the queue. An error is returned if the queue is empty.

func (*Queue[T]) Push

func (ns *Queue[T]) Push(t *T)

Push will push new data of type [T any] onto the queue.

func (*Queue[T]) Truncate

func (ns *Queue[T]) Truncate()

Truncate removes all data from the tree. Complexity is O(1).

Jump to

Keyboard shortcuts

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