datarithims

package module
v0.0.0-...-d12524e Latest Latest
Warning

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

Go to latest
Published: May 15, 2022 License: MIT Imports: 0 Imported by: 0

README

datarithms

A collection of go algorithms and datastructures I might find useful to throw at a problem. All implemented with go 1.18 generics.

Documentation

Overview

Implementations of a doubly linked list.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CircularBuffer

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

A Double-ended-queue that is implemented using a circular dynamic buffer.

func NewCircularBuffer

func NewCircularBuffer[T any]() *CircularBuffer[T]

Creates a new empty CircularBuffer.

func (*CircularBuffer[T]) IsEmpty

func (d *CircularBuffer[T]) IsEmpty() bool

func (*CircularBuffer[T]) PeekBack

func (d *CircularBuffer[T]) PeekBack() T

func (*CircularBuffer[T]) PeekFront

func (d *CircularBuffer[T]) PeekFront() T

func (*CircularBuffer[T]) PopBack

func (d *CircularBuffer[T]) PopBack() T

func (*CircularBuffer[T]) PopFront

func (d *CircularBuffer[T]) PopFront() T

func (*CircularBuffer[T]) PushBack

func (d *CircularBuffer[T]) PushBack(value T)

func (*CircularBuffer[T]) PushFront

func (d *CircularBuffer[T]) PushFront(value T)

Pushes a value onto the front of the CircularBuffer.

func (*CircularBuffer[T]) Size

func (d *CircularBuffer[T]) Size() int

type Deque

type Deque[T any] interface {
	PushFront(value T)
	PushBack(value T)
	PopFront() T
	PopBack() T
	PeekFront() T
	PeekBack() T
	IsEmpty() bool
}

Deque is a double-ended queue

type List

type List[T any] struct {
	// The head of the list is the fist element
	Head *Node[T]
	// The tail of the list is the last element
	Tail *Node[T]
	// The number of elements in the list
	Size int
}

List[T] is a doubly linked list. It implements the dequeue interface.

func NewList

func NewList[T any]() *List[T]

func (*List[T]) IsEmpty

func (l *List[T]) IsEmpty() bool

func (*List[T]) PeekBack

func (l *List[T]) PeekBack() T

func (*List[T]) PeekFront

func (l *List[T]) PeekFront() T

func (*List[T]) PopBack

func (l *List[T]) PopBack() T

func (*List[T]) PopFront

func (l *List[T]) PopFront() T

func (*List[T]) PushBack

func (l *List[T]) PushBack(value T)

func (*List[T]) PushFront

func (l *List[T]) PushFront(value T)

type Node

type Node[T any] struct {
	Value T
	Next  *Node[T]
	Prev  *Node[T]
}

func FindBack

func FindBack[T comparable](list *List[T], value T) *Node[T]

func FindFront

func FindFront[T comparable](list *List[T], value T) *Node[T]

type Queue

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

A Queue that is implemented using a linked list.

func NewQueue

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

func (*Queue[T]) IsEmpty

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

func (*Queue[T]) Peek

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

func (*Queue[T]) Pop

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

func (*Queue[T]) Push

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

type Stack

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

Implements a stack using a linked list.

func NewCircularBufferStack

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

func NewListStack

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

func (*Stack[T]) Peek

func (s *Stack[T]) Peek() T

func (*Stack[T]) Pop

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

func (*Stack[T]) Push

func (s *Stack[T]) Push(value T)

Jump to

Keyboard shortcuts

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