shared

package
v0.0.0-...-7c7f050 Latest Latest
Warning

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

Go to latest
Published: May 9, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package shared contains shared code for all lib modules.

Index

Constants

This section is empty.

Variables

View Source
var (
	RealEast              = Direction{X: 1, Y: 0}
	RealSouth             = Direction{X: 0, Y: -1}
	RealWest              = Direction{X: -1, Y: 0}
	RealNorth             = Direction{X: 0, Y: 1}
	RealPrimaryDirections = []Direction{
		RealEast,
		RealSouth,
		RealWest,
		RealNorth,
	}
	RealSouthEast        = Direction{X: 1, Y: -1}
	RealSouthWest        = Direction{X: -1, Y: -1}
	RealNorthWest        = Direction{X: -1, Y: 1}
	RealNorthEast        = Direction{X: 1, Y: 1}
	RealMiddleDirections = []Direction{
		RealSouthEast,
		RealSouthWest,
		RealNorthWest,
		RealNorthEast,
	}

	DirNorth   = Direction{X: 0, Y: -1}
	DirEast    = Direction{X: 1, Y: 0}
	DirSouth   = Direction{X: 0, Y: 1}
	DirWest    = Direction{X: -1, Y: 0}
	Directions = []Direction{
		DirEast,
		{X: 1, Y: -1},
		DirNorth,
		{X: -1, Y: -1},
		DirWest,
		{X: -1, Y: 1},
		DirSouth,
		{X: 1, Y: 1},
	}
)
View Source
var (
	// Logger is the logger for the app.
	Logger *slog.Logger
)

Functions

func Abs

func Abs[T Number](i T) T

func Assert

func Assert(must bool, message string)

If "must" isn't true, panic with message "message".

func Die

func Die(err error, message string)

func DiffLocSets

func DiffLocSets(t *testing.T, expected, actual *gent.Set[Loc])

func DigitLength

func DigitLength(i int) int

func Hash

func Hash(s []int) uint64

Hash with DJB2.

func InitLogging

func InitLogging()

InitLogging initializes logging.

func InitNullLogging

func InitNullLogging()

func InitTestLogging

func InitTestLogging(tb testing.TB)

InitTestLogging creates an slog logger that writes to t.Log.

func IsDebugEnabled

func IsDebugEnabled() bool

func Max

func Max[T Number](a, b T) T

func Min

func Min[T Number](a, b T) T

func Or

func Or[T any](o bool, yes, no T) T

func ParseIntOrDie

func ParseIntOrDie(s string) int

func Pow

func Pow(b, e int) int

func ReadLinesFromFile

func ReadLinesFromFile(filep string) (lines []string, err error)

func SetupCPUProfiling

func SetupCPUProfiling(filen string) (callback func())

func SplitToBlocks

func SplitToBlocks(lines []string) [][]string

SplitToBlocks splits lines with empty / blank lines.

func StripPadding

func StripPadding(lines []string) []string

func SubString

func SubString(s string, length int) string

func ToColumns

func ToColumns(s []string) (left []string, right []string)

func ToIntTable

func ToIntTable(s []string) (table [][]int)

func ToInts

func ToInts(s []string) (nums []int, err error)

Types

type Board

type Board struct {
	ReadOnly bool
	// contains filtered or unexported fields
}

func NewBoard

func NewBoard(lines []string) *Board

func (*Board) Copy

func (v *Board) Copy() *Board

func (*Board) CountArea

func (v *Board) CountArea() int

func (*Board) FindOrDie

func (v *Board) FindOrDie(c rune) Loc

func (*Board) Get

func (v *Board) Get(loc Loc) (c rune, ok bool)

func (*Board) GetArea

func (v *Board) GetArea() int

GetArea return width*height.

func (*Board) GetHeight

func (v *Board) GetHeight() int

func (*Board) GetInt

func (v *Board) GetInt(loc Loc) (i int, ok bool)

func (*Board) GetIntOrDie

func (v *Board) GetIntOrDie(loc Loc) int

func (*Board) GetLines

func (v *Board) GetLines() []string

func (*Board) GetOrDie

func (v *Board) GetOrDie(loc Loc) rune

func (*Board) GetWidth

func (v *Board) GetWidth() int

func (*Board) Iter

func (v *Board) Iter(cb BoardIterCb)

func (*Board) NextTo

func (v *Board) NextTo(loc Loc, c any, includeCorners bool) []Loc

NextTo return adjacent locations that contains c (rune or []rune).

func (*Board) Set

func (v *Board) Set(loc Loc, c rune)

type BoardIterCb

type BoardIterCb func(loc Loc, c rune) bool

Loc is in proper x-y coordinates.

2| 1| 0| ..--- ..012

type Direction

type Direction struct {
	X int
	Y int
}

func (Direction) TurnRealLeft

func (v Direction) TurnRealLeft() Direction

func (Direction) TurnRealRight

func (v Direction) TurnRealRight() Direction

func (Direction) TurnRight

func (v Direction) TurnRight() Direction
type Link[T any] struct {
	Item   T
	Parent *Link[T]
}

Link is a link in a linked list.

func AddLink[T any](parent *Link[T], item T) *Link[T]

AddLink adds a new link to a linked list.

type Loc

type Loc struct {
	X int
	Y int
}

func ParseLoc

func ParseLoc(s string) Loc

func (Loc) Delta

func (v Loc) Delta(delta Loc) Loc

func (Loc) Rev

func (v Loc) Rev() Loc

func (Loc) ToString

func (v Loc) ToString() string

type Number

type Number interface {
	uint | uint8 | uint16 | uint32 | uint64 | int | int8 | int16 | int32 | int64 | float32 | float64
}

type Pair

type Pair[T any] struct {
	First  T
	Second T
}

func NewPair

func NewPair[T any](first, second T) Pair[T]

func (Pair[T]) String

func (v Pair[T]) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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