Documentation
¶
Index ¶
- Variables
- func NumericMaxValue[W Numeric]() W
- func NumericZeroValue[W Numeric]() W
- type BasicTree
- type DoubleLinkedLister
- type Edge
- type Finder
- type Graph
- type HashMapper
- type Numeric
- type PriorityQueuer
- type Queuer
- type SearchBinaryTreeNode
- type SearchBinaryTreer
- type SimpleLinkedLister
- type Sizer
- type Stacker
- type Tree
- func (t *Tree[T]) BreadFirstSearch(value T) bool
- func (t *Tree[T]) DeleteWithDescendants(node *TreeNode[T]) error
- func (t *Tree[T]) DeleteWithoutDescendants(node *TreeNode[T]) error
- func (t *Tree[T]) DepthFirstSearch(value T) bool
- func (t *Tree[T]) Leaves() []*TreeNode[T]
- func (t *Tree[T]) PushAt(in *TreeNode[T], val T) (*TreeNode[T], error)
- func (t *Tree[T]) Root() *TreeNode[T]
- func (t *Tree[T]) Size() int64
- type TreeNode
Constants ¶
This section is empty.
Variables ¶
var ( ErrVertexNotFound = errors.New("vertex not found") ErrEdgeNotFound = errors.New("edge not found") ErrVertexAlreadyExists = errors.New("vertex already exists") ErrFindingShortestPath = errors.New("can not find shortest path") )
var ( ErrEmptyDoubleLinkedList = errors.New("empty list") ErrIndexOutOfRangeInDoubleLinkedList = errors.New("index out of range") )
var ( ErrEmptySimpleLinkedList = errors.New("empty list") ErrIndexOutOfRangeInSimpleLinkedList = errors.New("index out of range") )
var ( ErrEmptyTree = errors.New("empty tree") ErrInputNodeNil = errors.New("input node is nil") ErrCannotDeleteRoot = errors.New("cannot delete the root node without its descendants") ErrNodeNotFound = errors.New("node not found") )
var (
ErrEmptyQueue = errors.New("empty queue")
)
ErrEmptyQueue tolds the queue is empty
var (
ErrEmptyStack = errors.New("empty stack")
)
ErrEmptyStack tolds the stack is empty
var (
ErrHashMapKeyNotFound = errors.New("hash map key not found")
)
var (
ErrPriorityQueueEmpty = errors.New("priority queue is empty")
)
var (
ErrorSearchBinaryTreeValueNotFound = errors.New("value not found")
)
Functions ¶
func NumericMaxValue ¶
func NumericMaxValue[W Numeric]() W
NumericMaxValue returns the maximum possible value for a given numeric type W.
func NumericZeroValue ¶
func NumericZeroValue[W Numeric]() W
NumericZeroValue returns the zero value for the numeric type W.
Types ¶
type BasicTree ¶
type BasicTree[T comparable] interface { Sizer[T] PushAt(in *TreeNode[T], val T) (*TreeNode[T], error) DeleteWithDescendants(node *TreeNode[T]) error DeleteWithoutDescendants(node *TreeNode[T]) error Root() *TreeNode[T] Leaves() []*TreeNode[T] BreadFirstSearch(value T) bool DepthFirstSearch(value T) bool }
BasicTree define the basic operations of a tree
func NewTree ¶
func NewTree[T comparable](value T) BasicTree[T]
NewTree creates a new tree with a root node
type DoubleLinkedLister ¶
type DoubleLinkedLister[T comparable] interface { Sizer[T] Finder[T] PushAt(index int, value T) error PopAt(index int) (T, error) First() (T, error) Last() (T, error) GetAt(index int) (T, error) }
DoubleLinkedLister define the basic operations of a double linked list
func NewDoubleLinkedList ¶
func NewDoubleLinkedList[T comparable]() DoubleLinkedLister[T]
NewDoubleLinkedList creates a new double linked list
type Edge ¶
type Edge[T comparable, W any] struct { From T To T Weight W }
Edge represents an edge in a graph with a source, destination, and weight.
type Finder ¶
type Finder[T comparable] interface { Find(value T) bool }
Finder define a way to check if an element exists or not
type Graph ¶
type Graph[T comparable, W Numeric] interface { AddVertex(vertex T) error RemoveVertex(vertex T) error AddEdge(from, to T, weight W) error RemoveEdge(from, to T) error HasEdge(from, to T) bool Neighbors(vertex T) (map[T]W, error) Weight(from, to T) (W, error) Vertices() []T Edges() []Edge[T, W] Degree(vertex T) (int, error) InDegree(vertex T) (int, error) Transpose() Graph[T, W] IsDirected() bool ShortestPath(from, to T) ([]T, error) }
Graph represents a generic weighted graph with advanced operations
func NewAdjacencyListGraph ¶
func NewAdjacencyListGraph[T comparable, W Numeric](directed bool) Graph[T, W]
NewAdjacencyListGraph creates a new weighted adjacency list graph.
func NewAdjacencyMatrixGraph ¶
func NewAdjacencyMatrixGraph[T comparable, W Numeric](directed bool) Graph[T, W]
NewAdjacencyMatrixGraph creates a new weighted adjacency matrix graph.
type HashMapper ¶
type HashMapper[K comparable, V comparable] interface { Finder[V] Sizer[V] PushAt(key K, value V) PopAt(key K) (V, error) Has(key K) bool GetAt(key K) (V, error) }
HashMapper define the basic operations of a hash map
func NewHashMap ¶
func NewHashMap[K comparable, V comparable]() HashMapper[K, V]
NewHashMap creates a new emoty HashMap
type Numeric ¶
type Numeric interface { constraints.Integer | constraints.Float }
type PriorityQueuer ¶
type PriorityQueuer[T comparable] interface { Sizer[T] Push(value T) Pop() (T, error) Top() (T, error) }
func NewPriorityQueue ¶
func NewPriorityQueue[T comparable](compare func(a, b T) int) PriorityQueuer[T]
NewPriorityQueue creates a new priority queue
type Queuer ¶
type Queuer[T comparable] interface { Sizer[T] Finder[T] Pop() (T, error) Push(value T) Top() (T, error) Bottom() (T, error) }
Queuer define the basic operations of a queue
type SearchBinaryTreeNode ¶
type SearchBinaryTreeNode[T any] struct { // contains filtered or unexported fields }
SearchBinaryTreeNode represents a node in the search binary tree
type SearchBinaryTreer ¶
type SearchBinaryTreer[T comparable] interface { Finder[T] Sizer[T] Push(value T) Delete(value T) error Root() *SearchBinaryTreeNode[T] }
func NewSearchBinaryTree ¶
func NewSearchBinaryTree[T comparable](compare func(a, b T) int) SearchBinaryTreer[T]
NewSearchBinaryTree creates a new binary search tree
type SimpleLinkedLister ¶
type SimpleLinkedLister[T comparable] interface { Sizer[T] Finder[T] PushAt(index int, value T) error PopAt(index int) (T, error) First() (T, error) Last() (T, error) GetAt(index int) (T, error) }
SimpleLinkedLister define the basic operations of a simple linked list
func NewSimpleLinkedList ¶
func NewSimpleLinkedList[T comparable]() SimpleLinkedLister[T]
NewSimpleLinkedList creates a new simple linked list
type Sizer ¶
type Sizer[T comparable] interface { Size() int64 }
Sizer define the size of the structure
type Stacker ¶
type Stacker[T comparable] interface { Sizer[T] Finder[T] Pop() (T, error) Push(value T) Top() (T, error) Bottom() (T, error) }
Stacker define the basic operations of a stack
type Tree ¶
type Tree[T comparable] struct { // contains filtered or unexported fields }
func (*Tree[T]) BreadFirstSearch ¶
BreadFirstSearch find an element
func (*Tree[T]) DeleteWithDescendants ¶
DeleteWithDescendants delete a node and all its subnodes
func (*Tree[T]) DeleteWithoutDescendants ¶
DeleteWithoutDescendants delete a node and pass its children to its parent
func (*Tree[T]) DepthFirstSearch ¶
DepthFirstSearch find an element
type TreeNode ¶
type TreeNode[T comparable] struct { // contains filtered or unexported fields }
TreeNode is a node in a tree that stores a value and a list of children nodes