queue

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2023 License: MIT Imports: 0 Imported by: 1

README

go version license version

queue

queue is a lightweight package that provides queue and deque implementation with high performance in Go.
It also performs better than the built-in container/list package for any operation.

Documentation

Install

go get github.com/erfanmomeniii/queue

Next, include it in your application:

import "github.com/erfanmomeniii/queue"

Quick Start

The following example illustrates how to use this package for creating an instance and performing any operation with it:

package main

import (
	"fmt"
	"github.com/erfanmomeniii/queue"
)

func main() {
	q := queue.New()
	q.PushFront(1)
	q.PushFront("hi")
	q.PushBack(3.14)
	// q => [ "hi", 1, 3.14]

	fmt.Println(q.Front())
	// hi
	fmt.Println(q.Back())
	// 3.14

	q.PopBack()
	q.PopFront()
	fmt.Println(q.Front())
	// 1
}

Usage

type Queue
type Queue struct {
	front *Node
	back  *Node
}

Queue is an instantiation of the queue.

func New
func New() *Queue

New creates a new instance of a queue.

func PushFront
func (q *Queue) PushFront(value any)

PushFront adds a new element at the beginning of the queue.

func PushBack
func (q *Queue) PushBack(value any)

PushBack adds a new element at the end of the queue.

func PopFront
func (q *Queue) PopFront() (value any)

PopFront retrieves and removes the value of the first element in the queue.

func PopBack
func (q *Queue) PopBack() (value any)

PopBack retrieves and removes the value of the last element in the queue.

func Front
func (q *Queue) Front() (value any)

Front returns the value of front elements of the queue.

func Back
func (q *Queue) Back() (value any)

Back returns the value of last elements of the queue.

func Size
func (q *Queue) Size() (s int)

Size returns size of the queue.

Benchmarks

$ cd benchmarks
$ go test -bench .

Contributing

Pull requests are welcome. For changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

Queue is an instantiation of the queue.

func New

func New() *Queue

New creates a new instance of a queue.

func (*Queue) Back

func (q *Queue) Back() (value any)

Back returns the value of last elements of the queue.

func (*Queue) Front

func (q *Queue) Front() (value any)

Front returns the value of front elements of the queue.

func (*Queue) PopBack

func (q *Queue) PopBack() (value any)

PopBack retrieves and removes the value of the last element in the queue.

func (*Queue) PopFront

func (q *Queue) PopFront() (value any)

PopFront retrieves and removes the value of the first element in the queue.

func (*Queue) PushBack

func (q *Queue) PushBack(value any)

PushBack adds a new element at the end of the queue.

func (*Queue) PushFront

func (q *Queue) PushFront(value any)

PushFront adds a new element at the beginning of the queue.

func (*Queue) Size added in v1.0.2

func (q *Queue) Size() (s int)

Size returns size of the queue.

Jump to

Keyboard shortcuts

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