snippets

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package snippets は SNIPPETS.md と等価な内容を 1 ファイルにまとめたもの。 このファイル自体がビルド・テスト対象となるため、SNIPPETS.md の各ブロックが 単独でコンパイル可能であることを保証する。

実利用ではこのファイルを import せず、SNIPPETS.md の該当セクションをコピペして使う。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs[T Number](x T) T

func BFS

func BFS(g AdjList, src int) []int

func BinSearch

func BinSearch[T Ordered](xs []T, target T) int

func BinSearchFunc

func BinSearchFunc(n int, pred func(i int) bool) int

func Chunk

func Chunk[T any](xs []T, n int) [][]T

func Clamp

func Clamp[T Number](x, lo, hi T) T

func Contains

func Contains[T comparable](xs []T, target T) bool

func CountBy

func CountBy[T any, K comparable](xs []T, fn func(T) K) map[K]int

func CountChars

func CountChars(s string) map[rune]int

func DFS

func DFS(g AdjList, src int) []int

func Dijkstra

func Dijkstra(g AdjList, src int) []int64

func Filter

func Filter[T any](xs []T, pred func(T) bool) []T

func GCD

func GCD[T Integer](a, b T) T

func IndexOf

func IndexOf[T comparable](xs []T, target T) int

func IsAnagram

func IsAnagram(a, b string) bool

func IsPalindrome

func IsPalindrome(s string) bool

func IsPalindromeFold

func IsPalindromeFold(s string) bool

func IsPrime

func IsPrime(n int) bool

func LCM

func LCM[T Integer](a, b T) T

func LowerBound

func LowerBound[T Ordered](xs []T, target T) int

func Map

func Map[T, U any](xs []T, fn func(T) U) []U

func Max

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

func Min

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

func ModPow

func ModPow(base, exp, m int64) int64

func NewStdoutWriter

func NewStdoutWriter() *bufio.Writer

func Reduce

func Reduce[T, U any](xs []T, init U, fn func(U, T) U) U

func Reverse

func Reverse[T any](xs []T) []T

func ReverseInPlace

func ReverseInPlace[T any](xs []T)

func ReverseString

func ReverseString(s string) string

func Sieve

func Sieve(n int) []bool

func Sum

func Sum[T Number](xs []T) T

func Unique

func Unique[T comparable](xs []T) []T

func UpperBound

func UpperBound[T Ordered](xs []T, target T) int

Types

type AdjList

type AdjList [][]Edge

type Deque

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

func NewDeque

func NewDeque[T any]() *Deque[T]

func (*Deque[T]) Back

func (d *Deque[T]) Back() (T, bool)

func (*Deque[T]) Front

func (d *Deque[T]) Front() (T, bool)

func (*Deque[T]) IsEmpty

func (d *Deque[T]) IsEmpty() bool

func (*Deque[T]) Len

func (d *Deque[T]) Len() int

func (*Deque[T]) PopBack

func (d *Deque[T]) PopBack() (T, bool)

func (*Deque[T]) PopFront

func (d *Deque[T]) PopFront() (T, bool)

func (*Deque[T]) PushBack

func (d *Deque[T]) PushBack(v T)

func (*Deque[T]) PushFront

func (d *Deque[T]) PushFront(v T)

type Edge

type Edge struct {
	To int
	W  int
}

type Integer

type Integer interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Number

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

type Ordered

type Ordered interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
		~float32 | ~float64 | ~string
}

type PQ

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

func NewPQ

func NewPQ[T any](less func(a, b T) bool) *PQ[T]

func NewPQFromSlice

func NewPQFromSlice[T any](items []T, less func(a, b T) bool) *PQ[T]

func (*PQ[T]) IsEmpty

func (p *PQ[T]) IsEmpty() bool

func (*PQ[T]) Len

func (p *PQ[T]) Len() int

func (*PQ[T]) Peek

func (p *PQ[T]) Peek() (T, bool)

func (*PQ[T]) Pop

func (p *PQ[T]) Pop() (T, bool)

func (*PQ[T]) Push

func (p *PQ[T]) Push(v T)

type Queue

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

func NewQueue

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

func (*Queue[T]) IsEmpty

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

func (*Queue[T]) Len

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

func (*Queue[T]) Peek

func (q *Queue[T]) Peek() (T, bool)

func (*Queue[T]) Pop

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

func (*Queue[T]) Push

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

type Scanner

type Scanner struct {
	// contains filtered or unexported fields
}

func NewScannerFrom

func NewScannerFrom(r io.Reader) *Scanner

func NewStdinScanner

func NewStdinScanner() *Scanner

func (*Scanner) NextFloat

func (s *Scanner) NextFloat() float64

func (*Scanner) NextInt

func (s *Scanner) NextInt() int

func (*Scanner) NextInt64

func (s *Scanner) NextInt64() int64

func (*Scanner) NextInts

func (s *Scanner) NextInts(n int) []int

func (*Scanner) NextString

func (s *Scanner) NextString() string

type Stack

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

func NewStack

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

func (*Stack[T]) IsEmpty

func (s *Stack[T]) IsEmpty() bool

func (*Stack[T]) Len

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

func (*Stack[T]) Peek

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

func (*Stack[T]) Pop

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

func (*Stack[T]) Push

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

type Trie

type Trie struct {
	// contains filtered or unexported fields
}

func NewTrie

func NewTrie() *Trie

func (*Trie) Contains

func (t *Trie) Contains(word string) bool

func (*Trie) HasPrefix

func (t *Trie) HasPrefix(prefix string) bool

func (*Trie) Insert

func (t *Trie) Insert(word string)

type UnionFind

type UnionFind struct {
	// contains filtered or unexported fields
}

func NewUnionFind

func NewUnionFind(n int) *UnionFind

func (*UnionFind) Find

func (uf *UnionFind) Find(x int) int

func (*UnionFind) Groups

func (uf *UnionFind) Groups() int

func (*UnionFind) Same

func (uf *UnionFind) Same(a, b int) bool

func (*UnionFind) Size

func (uf *UnionFind) Size(x int) int

func (*UnionFind) Union

func (uf *UnionFind) Union(a, b int) bool

Jump to

Keyboard shortcuts

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