list

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2025 License: ISC Imports: 1 Imported by: 0

README

List

Data Structure Description
Queue First-in first-out (FIFO)
Stack Last-in first-out (LIFO)

Documentation

Overview

Package list implements list data structures.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Queue

type Queue[T any] interface {
	// Size returns the number of values in the queue.
	Size() int
	// IsEmpty returns true if the queue is empty.
	IsEmpty() bool
	// Enqueue adds a new value to the queue.
	Enqueue(T)
	// Dequeue removes a value from the queue.
	Dequeue() (T, bool)
	// Peek returns the next value in queue without removing it from the queue.
	Peek() (T, bool)
	// Contains returns true if a given value is already in the queue.
	Contains(T) bool
}

Queue represents a queue abstract data type.

func NewQueue

func NewQueue[T any](nodeSize int, equal generic.EqualFunc[T]) Queue[T]

NewQueue creates a new array-list queue.

type SoftQueue added in v0.4.2

type SoftQueue[T any] interface {
	// Size returns the number of values in the queue.
	Size() int

	// IsEmpty returns true if the queue is empty.
	IsEmpty() bool

	// Enqueue inserts a new value to the queue.
	// It returns the index of the newly enqueued value in the queue.
	Enqueue(T) int

	// Dequeue deletes a value from the queue.
	// The deletion is soft and the entries remain in the queue.
	// Deleted entries are searchable using the Contains method.
	// The second return value is the index of the dequeued value in the queue.
	Dequeue() (T, int)

	// Peek returns the next value in queue without deleting it from the queue.
	// The second return value is the index of the peeked value in the queue.
	Peek() (T, int)

	// Contains returns true if a given value is either in the queue or deleted in the past.
	// If the value is found, its index in the queue is returned; otherwise, -1 is returned.
	Contains(T) int

	// Values returns the list of all values in the queue including the deleted ones.
	Values() []T
}

SoftQueue represents the abstract data type for a queue with soft deletion.

func NewSoftQueue added in v0.4.2

func NewSoftQueue[T any](equal generic.EqualFunc[T]) SoftQueue[T]

NewSoftQueue creates a new array-list queue with soft deletion. Deleted entries remain in the queue and are searchable.

type Stack

type Stack[T any] interface {
	// Size returns the number of values on the stack.
	Size() int
	// IsEmpty returns true if the stack is empty.
	IsEmpty() bool
	// Enqueue adds a new value to the stack.
	Push(T)
	// Dequeue removes a value from the stack.
	Pop() (T, bool)
	// Peek returns the next value on stack without removing it from the stack.
	Peek() (T, bool)
	// Contains returns true if a given value is already on the stack.
	Contains(T) bool
}

Stack represents a stack abstract data type.

func NewStack

func NewStack[T any](nodeSize int, equal generic.EqualFunc[T]) Stack[T]

NewStack creates a new array-list stack.

Jump to

Keyboard shortcuts

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