utils

package
v0.0.0-...-12cf40b Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	UP    = Direction(NewCoordinate(0, -1))
	DOWN  = Direction(NewCoordinate(0, 1))
	LEFT  = Direction(NewCoordinate(-1, 0))
	RIGHT = Direction(NewCoordinate(1, 0))
)
View Source
var (
	ErrKeyAlreadyExists = errors.New("key already exists")
)

Functions

func ExecutePerLine

func ExecutePerLine(r io.Reader, f func(line string) error)

func IntSliceSum

func IntSliceSum(s []int) int

func LeastCommonMultiple

func LeastCommonMultiple(nums []int) int

func NevilleInterpolation

func NevilleInterpolation(xs []int, ys []int, x int) int

func PrimeFactorization

func PrimeFactorization(num int) []int

func ReadFile

func ReadFile(name string) *os.File

func SliceFilter

func SliceFilter[T any](s []T, f func(v T) bool) []T

func SliceMap

func SliceMap[T any, U any](s []T, f func(v T) U) []U

func StrSliceToIntSlice

func StrSliceToIntSlice(strs []string) ([]int, error)

Types

type Char

type Char rune

Char is just a rune that implements Stringer so that printing out runes is nicer

func (Char) String

func (c Char) String() string

type ConnectionMap

type ConnectionMap[K comparable] map[K]map[K]int

func (ConnectionMap[K]) Betweeness

func (cMap ConnectionMap[K]) Betweeness() map[K]float64

func (ConnectionMap[K]) Dijkstra

func (cMap ConnectionMap[K]) Dijkstra(source K) (map[K]int, map[K]K)

func (ConnectionMap[K]) DijkstraWithDest

func (cMap ConnectionMap[K]) DijkstraWithDest(source K, destination K) int

func (ConnectionMap[K]) EdgeBetweeness

func (cMap ConnectionMap[K]) EdgeBetweeness() map[K]map[K]float64

func (ConnectionMap[K]) LongestDijkstraWithDest

func (cMap ConnectionMap[K]) LongestDijkstraWithDest(source K, destination K) (int, []K)

type Coordinate

type Coordinate struct {
	X int
	Y int
}

func NewCoordinate

func NewCoordinate(x int, y int) Coordinate

func (Coordinate) Add

func (c Coordinate) Add(c2 Coordinate) Coordinate

func (Coordinate) MoveDir

func (c Coordinate) MoveDir(dir Direction) Coordinate

func (Coordinate) StepsToCoordinate

func (c Coordinate) StepsToCoordinate(c2 Coordinate) int

func (Coordinate) String

func (c Coordinate) String() string

func (Coordinate) Sub

func (c Coordinate) Sub(c2 Coordinate) Coordinate

type Coordinate3D

type Coordinate3D[T Number] struct {
	X T
	Y T
	Z T
}

func NewCoordinate3D

func NewCoordinate3D[T Number](x, y, z T) Coordinate3D[T]

func (Coordinate3D[T]) String

func (c Coordinate3D[T]) String() string

func (Coordinate3D[T]) Translate

func (c Coordinate3D[T]) Translate(x, y, z T) Coordinate3D[T]

type Direction

type Direction Coordinate

func (Direction) String

func (d Direction) String() string

type Number

type Number interface {
	int | float64
}

type PriorityQueue

type PriorityQueue[K comparable, P cmp.Ordered] struct {
	// contains filtered or unexported fields
}

func NewPriorityQueue

func NewPriorityQueue[K comparable, P cmp.Ordered]() *PriorityQueue[K, P]

func (*PriorityQueue[K, P]) Init

func (pq *PriorityQueue[K, P]) Init(vals map[K]P)

func (*PriorityQueue[_, _]) Len

func (pq *PriorityQueue[_, _]) Len() int

func (*PriorityQueue[K, P]) Pop

func (pq *PriorityQueue[K, P]) Pop() (K, P)

func (*PriorityQueue[K, P]) Push

func (pq *PriorityQueue[K, P]) Push(v K, priority P)

func (*PriorityQueue[K, P]) SetPriorityOrder

func (pq *PriorityQueue[K, P]) SetPriorityOrder(inverseOrder bool)

func (*PriorityQueue[K, P]) Update

func (pq *PriorityQueue[K, P]) Update(v K, priority P)

type Queue

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

func NewQueue

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

func (*Queue[T]) Len

func (q *Queue[T]) Len() int

func (*Queue[T]) Pop

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

func (*Queue[T]) Push

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

type Stack

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

func NewStack

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

func (*Stack[T]) Len

func (s *Stack[T]) Len() int

func (*Stack[T]) Pop

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

func (*Stack[T]) Push

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

Jump to

Keyboard shortcuts

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