Queue FIFO implementation in Go
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
LICENSE
README.md
queue.go
queue_test.go

README.md

queue

-- import "github.com/vedhavyas/queue"

Usage

type Queue

type Queue struct {}

Queue represents the FIFO list of items

func (*Queue) Dequeue

func (q *Queue) Dequeue() (interface{}, error)

Dequeue returns the first item from queue: O(1)

Returns an error if queue empty/out of bounds

func (*Queue) Enqueue

func (q *Queue) Enqueue(item interface{})

Enqueue add the item to the queue: O(1)

func (*Queue) Get

func (q *Queue) Get(i int) (interface{}, error)

Get returns the item at the given index from the list: O(n)

Returns an error if queue empty/out of bounds

func (*Queue) Len

func (q *Queue) Len() int

Len returns the items count in the queue

func (*Queue) Peak

func (q *Queue) Peak() (interface{}, error)

Peak returns the next value in queue but does not remove from queue: O(1)

Returns error if queue empty

func (*Queue) PeakAt

func (q *Queue) PeakAt(i int) (interface{}, error)

PeakAt returns the item at the index i from the queue: O(n)

Returns error if queue empty/out of bounds

func (*Queue) String

func (q *Queue) String() string

String dumps the queue in human readable format: O(n)