util

package
v0.0.0-...-e215f18 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(x int) int

func ByteToInt

func ByteToInt(b byte) (int, error)

Convert a rune value between '0' and '9' to a int value

func DigitToRune

func DigitToRune(d int) rune

func FirstRune

func FirstRune(text string) rune

Return the first rune in the string. Will panic on a zero length string

func InsertAt

func InsertAt[T any](data []T, index int, value T) []T

func InsertSorted

func InsertSorted[S ~[]E, E constraints.Ordered](data S, value E) S

func InsertSortedF

func InsertSortedF[T any](data []T, value T, less func(left, right T) bool) []T

func IsWhitespace

func IsWhitespace(s string) bool

func Max

func Max[T constraints.Ordered](x T, y T) T

func MaxSlice

func MaxSlice[T constraints.Ordered](data []T) T

func Min

func Min[T constraints.Ordered](x T, y T) T

func MinSlice

func MinSlice[T constraints.Ordered](data []T) T

func MustReadLines

func MustReadLines(f embed.FS, name string) []string

func ParseCommaSepInt

func ParseCommaSepInt(line string) ([]int, error)

func ParseLines

func ParseLines[T any](lines []string, parse func(string) (T, error)) ([]T, error)

func Project

func Project[T any, U any](data []T, project func(T) U) []U

func ReadAndParseLines

func ReadAndParseLines[T any](f embed.FS, name string, parse func(string) (T, error)) ([]T, error)

func ReadAsSingleLine

func ReadAsSingleLine(f embed.FS, name string) (string, error)

func ReadLines

func ReadLines(f embed.FS, name string) ([]string, error)

func ReadLinesAsInt

func ReadLinesAsInt(f embed.FS, name string) ([]int, error)

func Require

func Require(cond bool)

func ReverseSlice

func ReverseSlice[T any](slice []T)

func RuneToInt

func RuneToInt(r rune) (int, error)

Convert a rune value between '0' and '9' to a int value

func SetAll

func SetAll[T any](values []T, value T)

func SplitOnWhiteSpace

func SplitOnWhiteSpace(line string) []string

func StartsWithRune

func StartsWithRune(s string, r rune) bool

func StartsWithString

func StartsWithString(s, prefix string) bool

func StringToInt

func StringToInt(s string) int

Types

type Grid

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

func NewGrid

func NewGrid[T any](row, column int) *Grid[T]

func ParseGridFromLines

func ParseGridFromLines[T any](lines []string, parseRune func(int, int, rune) (T, error)) (*Grid[T], error)

Parse out a grid from a series of single digit entries on a line like the following

0123 4567

func (*Grid[T]) Columns

func (g *Grid[T]) Columns() int

func (*Grid[T]) Count

func (g *Grid[T]) Count() int

func (*Grid[T]) Index

func (g *Grid[T]) Index(row, column int) int

func (*Grid[T]) Resize

func (g *Grid[T]) Resize(row, column int)

func (*Grid[T]) RowColumn

func (g *Grid[T]) RowColumn(index int) (row, column int)

func (*Grid[T]) Rows

func (g *Grid[T]) Rows() int

func (*Grid[T]) SetAll

func (g *Grid[T]) SetAll(value T)

func (*Grid[T]) SetValue

func (g *Grid[T]) SetValue(row, column int, value T)

func (*Grid[T]) Value

func (g *Grid[T]) Value(row, column int) T

type Queue

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

func NewQueue

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

func (*Queue[T]) Dequeue

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

func (*Queue[T]) Enqueue

func (q *Queue[T]) Enqueue(value T)

func (*Queue[T]) IsEmpty

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

type Stack

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

func NewStack

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

func (*Stack[T]) Length

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

func (*Stack[T]) Peek

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

func (*Stack[T]) Pop

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

func (*Stack[T]) Push

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

func (*Stack[T]) Reverse

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

type VirtualGrid

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

func NewVirtualGrid

func NewVirtualGrid[T any]() *VirtualGrid[T]

func NewVirtualGridWithDefaultValue

func NewVirtualGridWithDefaultValue[T any](value T) *VirtualGrid[T]

func (*VirtualGrid[T]) Columns

func (grid *VirtualGrid[T]) Columns() int

func (*VirtualGrid[T]) MaxColumn

func (grid *VirtualGrid[T]) MaxColumn() int

func (*VirtualGrid[T]) MaxRow

func (grid *VirtualGrid[T]) MaxRow() int

func (*VirtualGrid[T]) MinColumn

func (grid *VirtualGrid[T]) MinColumn() int

func (*VirtualGrid[T]) MinRow

func (grid *VirtualGrid[T]) MinRow() int

func (*VirtualGrid[T]) Rows

func (grid *VirtualGrid[T]) Rows() int

func (*VirtualGrid[T]) SetValue

func (grid *VirtualGrid[T]) SetValue(row, column int, value T)

func (*VirtualGrid[T]) Value

func (grid *VirtualGrid[T]) Value(row, column int) T

Jump to

Keyboard shortcuts

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