utilities

package
v0.0.0-...-35c3acc Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateSlice

func CreateSlice[T comparable](size int, initial T) []T

func ElementHammingDistance

func ElementHammingDistance[T comparable](s1 []T, s2 []T) int

func ErrorCheck

func ErrorCheck(e error)

func IntsToStrings

func IntsToStrings(intSlice []int) []string

func OpenFile

func OpenFile(path string) (*bufio.Scanner, *os.File)

func StringsToInts

func StringsToInts(stringSlice []string) []int

Types

type Coordinates

type Coordinates struct {
	Row int
	Col int
}

******************************************* // Coordinate structure and related functions. // ******************************************* //

func (Coordinates) Abs

func (coord Coordinates) Abs() Coordinates

func (Coordinates) Add

func (coord Coordinates) Add(otherCoord Coordinates) Coordinates

func (Coordinates) Scale

func (coord Coordinates) Scale(scalar int) Coordinates

func (Coordinates) Subtract

func (coord Coordinates) Subtract(otherCoord Coordinates) Coordinates

type Grid

type Grid[T comparable] struct {
	Data [][]T
}

************************************* // Grid structure and related functions. // ************************************* //

func GridFromFile

func GridFromFile(path string) *Grid[rune]

func NewGrid

func NewGrid[T comparable]() *Grid[T]

func (*Grid[T]) AddColumn

func (g *Grid[T]) AddColumn(index int, column []T) error

func (*Grid[T]) AddRow

func (g *Grid[T]) AddRow(index int, row []T) error

Row specific functions.

func (*Grid[T]) AppendColumn

func (g *Grid[T]) AppendColumn(column []T)

func (*Grid[T]) AppendRow

func (g *Grid[T]) AppendRow(row []T)

func (*Grid[T]) ColContains

func (g *Grid[T]) ColContains(index int, item T) bool

func (*Grid[_]) ColSize

func (g *Grid[_]) ColSize() int

func (*Grid[T]) Contains

func (g *Grid[T]) Contains(item T) bool

func (*Grid[T]) CoordInGrid

func (g *Grid[T]) CoordInGrid(coord Coordinates) bool

func (*Grid[T]) Get

func (g *Grid[T]) Get(rowIndex int, columnIndex int) (T, error)

func (*Grid[T]) GetByCoord

func (g *Grid[T]) GetByCoord(coord Coordinates) (T, error)

func (*Grid[T]) GetColumn

func (g *Grid[T]) GetColumn(index int) ([]T, error)

func (*Grid[T]) GetRow

func (g *Grid[T]) GetRow(index int) ([]T, error)

func (*Grid[_]) PrintGrid

func (g *Grid[_]) PrintGrid()

func (*Grid[T]) RowContains

func (g *Grid[T]) RowContains(index int, item T) bool

Column specific functions.

func (*Grid[_]) RowSize

func (g *Grid[_]) RowSize() int

Size functions.

func (*Grid[T]) Search

func (g *Grid[T]) Search(item T) []Coordinates

General functions.

func (*Grid[_]) Serialize

func (g *Grid[_]) Serialize() string

func (*Grid[T]) Set

func (g *Grid[T]) Set(rowIndex int, columnIndex int, item T) error

func (*Grid[T]) SetByCoord

func (g *Grid[T]) SetByCoord(coord Coordinates, val T) error

func (*Grid[T]) SetColumn

func (g *Grid[T]) SetColumn(index int, column []T) error

func (*Grid[T]) SetRow

func (g *Grid[T]) SetRow(index int, row []T) error

func (*Grid[_]) Shape

func (g *Grid[_]) Shape() (int, int)

type MaxPriorityQueue

type MaxPriorityQueue[T comparable] struct {
	// contains filtered or unexported fields
}

func (MaxPriorityQueue) Len

func (pq MaxPriorityQueue) Len() int

func (MaxPriorityQueue[_]) Less

func (mpq MaxPriorityQueue[_]) Less(i, j int) bool

func (*MaxPriorityQueue) Pop

func (pq *MaxPriorityQueue) Pop() any

func (*MaxPriorityQueue) Push

func (pq *MaxPriorityQueue) Push(x any)

func (MaxPriorityQueue) Swap

func (pq MaxPriorityQueue) Swap(i, j int)

type MinPriorityQueue

type MinPriorityQueue[T comparable] struct {
	// contains filtered or unexported fields
}

func (MinPriorityQueue) Len

func (pq MinPriorityQueue) Len() int

func (MinPriorityQueue[_]) Less

func (mpq MinPriorityQueue[_]) Less(i, j int) bool

func (*MinPriorityQueue) Pop

func (pq *MinPriorityQueue) Pop() any

func (*MinPriorityQueue) Push

func (pq *MinPriorityQueue) Push(x any)

func (MinPriorityQueue) Swap

func (pq MinPriorityQueue) Swap(i, j int)

type PriorityElement

type PriorityElement[T comparable] struct {
	Value    T
	Priority int
}

type Set

type Set[K comparable] struct {
	// contains filtered or unexported fields
}

func NewSet

func NewSet[K comparable]() *Set[K]

func (*Set[K]) Add

func (s *Set[K]) Add(element K)

func (*Set[K]) Contains

func (s *Set[K]) Contains(element K) bool

func (*Set[K]) Size

func (s *Set[K]) Size() int

func (*Set[K]) ToSlice

func (s *Set[K]) ToSlice() []K

type Vector

type Vector struct {
	Origin    Coordinates
	Direction Coordinates
}

**************************************** // Vector structure (origin and direction). // **************************************** //

Jump to

Keyboard shortcuts

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