utils

package
v0.0.0-...-7700d31 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Why the fuck is this not part of the language

Index

Constants

This section is empty.

Variables

View Source
var DirFromOffset = map[Coord]Direction{
	{X: -1, Y: 0}: UP,
	{X: 1, Y: 0}:  DOWN,
	{X: 0, Y: -1}: LEFT,
	{X: 0, Y: 1}:  RIGHT,
}
View Source
var InverseDir = map[Direction]Direction{
	UP:    DOWN,
	DOWN:  UP,
	LEFT:  RIGHT,
	RIGHT: LEFT,
}
View Source
var Offsets = map[Direction]Coord{
	UP:    {X: -1, Y: 0},
	DOWN:  {X: 1, Y: 0},
	LEFT:  {X: 0, Y: -1},
	RIGHT: {X: 0, Y: 1},
}

Suposes (0,0) at top-left corner, with x going downwards and y going to the right

Functions

func Contains

func Contains[S ~[]E, E comparable](s S, e E) bool

func Remove

func Remove[S ~[]E, E comparable](s S, e E) S

func RemoveAt

func RemoveAt[S ~[]E, E any](s S, i int) S

Types

type Coord

type Coord struct {
	X int
	Y int
}

func (Coord) Add

func (c Coord) Add(other Coord) Coord

func (Coord) Scale

func (c Coord) Scale(factor int) Coord

func (Coord) Sub

func (c Coord) Sub(other Coord) Coord

type Direction

type Direction int
const (
	UP Direction = iota
	DOWN
	LEFT
	RIGHT
)

type PQItem

type PQItem[T comparable] struct {
	Value    T
	Priority int
	// contains filtered or unexported fields
}

type PriorityQueue

type PriorityQueue[T comparable] []*PQItem[T]

Uses container/heap for implementation Always pops the element with the lowest priority first

func NewPriorityQueue

func NewPriorityQueue[T comparable]() *PriorityQueue[T]

func (PriorityQueue[T]) IsEmpty

func (pq PriorityQueue[T]) IsEmpty() bool

func (PriorityQueue[T]) Len

func (pq PriorityQueue[T]) Len() int

func (PriorityQueue[T]) Less

func (pq PriorityQueue[T]) Less(i, j int) bool

func (*PriorityQueue[T]) Pop

func (pq *PriorityQueue[T]) Pop() any

func (*PriorityQueue[T]) PopItem

func (pq *PriorityQueue[T]) PopItem() T

func (*PriorityQueue[T]) Push

func (pq *PriorityQueue[T]) Push(x any)

func (*PriorityQueue[T]) PushItem

func (pq *PriorityQueue[T]) PushItem(value T, priority int)

func (PriorityQueue[T]) Swap

func (pq PriorityQueue[T]) Swap(i, j int)

type Queue

type Queue[T any] []T

Normal queue

func (Queue[T]) IsEmpty

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

func (*Queue[T]) Pop

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

func (*Queue[T]) Push

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

type Set

type Set[T comparable] map[T]struct{}

func (Set[T]) Add

func (s Set[T]) Add(t T)

func (Set[T]) Contains

func (s Set[T]) Contains(t T) bool

func (Set[T]) Remove

func (s Set[T]) Remove(t T)

func (Set[T]) Size

func (s Set[T]) Size() int

Jump to

Keyboard shortcuts

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