Skip to content

Latest commit

 

History

History
 
 

queue

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

queue

import "github.com/zyedidia/generic/queue"

Package queue provides an implementation of a First In First Out (FIFO) queue. The FIFO queue is implemented using the doubly-linked list from the 'list' package.

Example

{
	q := New[int]()
	q.Enqueue(1)
	q.Enqueue(2)

	q.Each(func(i int) {
		fmt.Println(i)
	})

}

Output

1
2

Example ($equeue)

{
	q := New[int]()
	q.Enqueue(1)

	fmt.Println(q.Dequeue())

}

Output

1

Example (%mpty_empty)

{
	q := New[int]()

	fmt.Println(q.Empty())

}

Output

true

Example (%mpty_nonempty)

{
	q := New[int]()
	q.Enqueue(1)

	fmt.Println(q.Empty())

}

Output

false

Example (%nqueue)

{
	q := New[int]()
	q.Enqueue(1)
}

Example (0eek)

{
	q := New[int]()
	q.Enqueue(1)

	fmt.Println(q.Peek())

}

Output

1

Index

type Queue

Queue is a simple First In First Out (FIFO) queue.

type Queue[T any] struct {
    // contains filtered or unexported fields
}

func New

func New[T any]() *Queue[T]

New returns an empty First In First Out (FIFO) queue.

func (*Queue[T]) Dequeue

func (q *Queue[T]) Dequeue() T

Dequeue removes and returns the item at the front of the queue.

A panic occurs if the queue is Empty.

func (*Queue[T]) Each

func (q *Queue[T]) Each(fn func(t T))

Each calls 'fn' on every item in the queue, starting with the least recently pushed element.

func (*Queue[T]) Empty

func (q *Queue[T]) Empty() bool

Empty returns true if the queue is empty.

func (*Queue[T]) Enqueue

func (q *Queue[T]) Enqueue(value T)

Enqueue inserts 'value' to the end of the queue.

func (*Queue[T]) Peek

func (q *Queue[T]) Peek() T

Peek returns the item at the front of the queue without removing it.

A panic occurs if the queue is Empty.

Generated by gomarkdoc