goutilsgit.mstar.dev/mstar/goutils/containers Index | Files

package containers

import "git.mstar.dev/mstar/goutils/containers"

Package containers contains implementations of a generic queue and stack

Index

Variables

var ErrEmptyQueue = errors.New("empty queue")
var ErrInvalidQueue = errors.New("invalid queue")

Types

type Queue

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

func BuildQueue

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

func (*Queue[T]) IsEmpty

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

IsEmpty checks if the queue is empty.

func (*Queue[T]) Pop

func (q *Queue[T]) Pop() (*T, error)

Pop removes the first element of the queue. It errors out if there is no element or the queue is invalid.

func (*Queue[T]) Push

func (q *Queue[T]) Push(elem *T) error

Push adds a new element to the end of the queue.

func (*Queue[T]) Top

func (q *Queue[T]) Top() (*T, error)

Top returns the first element of the queue without removing it. It errors out if there is no element or the queue is invalid.

type Stack

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

func BuildStack

func BuildStack[T any]() *Stack[T]

func (*Stack[T]) IsEmpty

func (s *Stack[T]) IsEmpty() bool

IsEmpty checks if the stack is currently empty.

func (*Stack[T]) Pop

func (s *Stack[T]) Pop() (*T, error)

Pop removes the first element at the top of the stack and returns it. It errors out if the stack is invalid or empty.

func (*Stack[T]) Push

func (s *Stack[T]) Push(e *T) error

Push adds a new element to the top of the stack. It errors out if the stack is invalid.

func (*Stack[T]) Top

func (s *Stack[T]) Top() (*T, error)

Top returns the first element at the top of the stack without removing it. It errors out if the stack is empty or invalid.

Source Files

generics.go queues.go stacks.go

Version
v1.15.0 (latest)
Published
Jun 6, 2025
Platform
linux/amd64
Imports
1 packages
Last checked
1 hour ago

Tools for package owners.