tl

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

README

tl

Golang generic utilities (Template Library)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Advance

func Advance[T any](iter Iter[T], count int)

func AntiJoin

func AntiJoin[T comparable](a, b []T) []T

func AntiJoinFn

func AntiJoinFn[T any](a, b []T, cmpFn func(a, b T) bool) (r []T)

func Avg

func Avg[T constraints.Integer | constraints.Float](a ...T) (r T)

func Contains

func Contains[T comparable](vs []T, e T) bool

func ContainsFn

func ContainsFn[T any](vs []T, cmpFn CompareFunc[T]) bool

func Delete

func Delete[T comparable](set []T, value T) []T

func Filter

func Filter[T any](set []T, cmpFn CompareFunc[T]) []T

func FilterInPlace

func FilterInPlace[T any](set []T, cmpFn CompareFunc[T]) []T

func Join

func Join[T comparable](a, b []T) []T

func JoinFn

func JoinFn[T any](a, b []T, cmpFn func(a, b T) bool) (r []T)

func Map

func Map[T, E any](set []T, fn func(T) E) []E

func Max

func Max[T constraints.Ordered](numbers ...T) (r T)

func Merge

func Merge[T comparable](a, b []T) (r []T)

func MergeFn

func MergeFn[T any](cmpFn func(a, b T) bool, a []T, more ...[]T) (r []T)

func Min

func Min[T constraints.Ordered](a, b T) (r T)

func SearchFn

func SearchFn[T any](vs []T, cmpFn CompareFunc[T]) int

func Sum

func Sum[T constraints.Integer | constraints.Float](a ...T) (r T)

Types

type Bytes

type Bytes Vec[byte]

func BytesFrom

func BytesFrom(bts []byte) Bytes

func NewBytes

func NewBytes(size, capacity int) Bytes

func (*Bytes) Append

func (b *Bytes) Append(bts ...byte)

func (Bytes) Cap

func (b Bytes) Cap() int

func (Bytes) Contains

func (b Bytes) Contains(c byte) bool

func (*Bytes) CopyFrom

func (b *Bytes) CopyFrom(b2 Bytes)

func (Bytes) Index

func (b Bytes) Index(c byte) int

func (Bytes) Len

func (b Bytes) Len() int

func (*Bytes) LimitReadFrom

func (b *Bytes) LimitReadFrom(r io.Reader, n int) (int64, error)

func (Bytes) LimitWriteTo

func (b Bytes) LimitWriteTo(w io.Writer, n int) (int64, error)

LimitWriteTo writes a limited amount from `b` to `w`.

func (*Bytes) Push

func (b *Bytes) Push(bts ...byte)

func (Bytes) ReadFrom

func (b Bytes) ReadFrom(r io.Reader) (int64, error)

func (*Bytes) Reserve

func (b *Bytes) Reserve(n int)

func (*Bytes) Resize

func (b *Bytes) Resize(n int)

func (Bytes) Slice

func (b Bytes) Slice(low, max int) Bytes

func (Bytes) String

func (b Bytes) String() string

String returns the `Bytes`' string representation.

func (Bytes) UnsafeString

func (b Bytes) UnsafeString() string

func (Bytes) WriteTo

func (b Bytes) WriteTo(w io.Writer) (int64, error)

type CompareFunc

type CompareFunc[T any] func(T) bool

type Iter

type Iter[T any] interface {
	Next() bool
	Get() T
	GetPtr() *T
}

type IterBidir

type IterBidir[T any] interface {
	Iter[T]

	Back() bool
}

type IterDrop

type IterDrop[T any] interface {
	Iter[T]

	Drop()
}

type IterDropBidir

type IterDropBidir[T any] interface {
	IterDrop[T]
	IterBidir[T]
}

type List

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

func (*List[T]) Back

func (list *List[T]) Back() (opt OptionalPtr[T])

func (*List[T]) Front

func (list *List[T]) Front() (opt OptionalPtr[T])

func (*List[T]) Iter

func (list *List[T]) Iter() IterDropBidir[T]

func (*List[T]) PopBack

func (list *List[T]) PopBack() (opt OptionalPtr[T])

func (*List[T]) PopFront

func (list *List[T]) PopFront() (opt OptionalPtr[T])

func (*List[T]) PushBack

func (list *List[T]) PushBack(v T) *ListElement[T]

func (*List[T]) PushFront

func (list *List[T]) PushFront(v T) *ListElement[T]

func (*List[T]) Reset

func (list *List[T]) Reset()

func (*List[T]) Size

func (list *List[T]) Size() int

type ListElement

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

func (*ListElement[T]) Drop

func (e *ListElement[T]) Drop()

func (*ListElement[T]) Get

func (e *ListElement[T]) Get() T

func (*ListElement[T]) GetPtr

func (e *ListElement[T]) GetPtr() *T

type Optional

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

func MakeOptional

func MakeOptional[T any](v T) (opt Optional[T])

func NewOptional

func NewOptional[T any](v *T) (opt Optional[T])

func None

func None[T any]() (opt Optional[T])

func (Optional[T]) From

func (opt Optional[T]) From(v T) Optional[T]

func (Optional[T]) Get

func (opt Optional[T]) Get() T

func (Optional[T]) HasValue

func (opt Optional[T]) HasValue() bool

func (Optional[T]) Or

func (opt Optional[T]) Or(v T) Optional[T]

func (Optional[T]) Ptr

func (opt Optional[T]) Ptr() *T

func (*Optional[T]) Reset

func (opt *Optional[T]) Reset()

func (*Optional[T]) Set

func (opt *Optional[T]) Set(v T)

type OptionalPtr

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

func MakeOptionalPtr

func MakeOptionalPtr[T any](v *T) (opt OptionalPtr[T])

func (OptionalPtr[T]) Get

func (opt OptionalPtr[T]) Get() *T

func (*OptionalPtr[T]) GetValue

func (opt *OptionalPtr[T]) GetValue() T

func (OptionalPtr[T]) HasValue

func (opt OptionalPtr[T]) HasValue() bool

func (OptionalPtr[T]) Or

func (opt OptionalPtr[T]) Or(v *T) OptionalPtr[T]

func (OptionalPtr[T]) Ptr

func (opt OptionalPtr[T]) Ptr() *T

func (*OptionalPtr[T]) Reset

func (opt *OptionalPtr[T]) Reset()

func (*OptionalPtr[T]) Set

func (opt *OptionalPtr[T]) Set(v *T)

type Pair

type Pair[T, U any] struct {
	// contains filtered or unexported fields
}

func MakePair

func MakePair[T, U any](t T, u U) Pair[T, U]

func (Pair[T, U]) Both

func (p Pair[T, U]) Both() (T, U)

func (Pair[T, U]) First

func (p Pair[T, U]) First() T

func (Pair[T, U]) Second

func (p Pair[T, U]) Second() U

func (Pair[T, U]) Swap

func (p Pair[T, U]) Swap() Pair[U, T]

type Queue

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

func (*Queue[T]) Front

func (q *Queue[T]) Front() (v Optional[T])

func (*Queue[T]) Pop

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

func (*Queue[T]) PushBack

func (q *Queue[T]) PushBack(data T)

func (*Queue[T]) PushFront

func (q *Queue[T]) PushFront(data T)

func (*Queue[T]) Reset

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

type Ring

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

Ring is a Multiple-Producer Multiple-Consumer (MPMC) circular buffer data structure.

func NewRing

func NewRing[T any](size int) *Ring[T]

NewRing returns a ring of type T with the size rounded up to the nearest power of 2.

func (*Ring[T]) Pop

func (ring *Ring[T]) Pop() (value T, ok bool)

func (*Ring[T]) Push

func (ring *Ring[T]) Push(fn T) bool

type Tree

type Tree[Key comparable, Value any] struct {
	// contains filtered or unexported fields
}

func (*Tree[Key, Value]) Data

func (tree *Tree[Key, Value]) Data() Optional[Value]

func (*Tree[Key, Value]) Del

func (tree *Tree[Key, Value]) Del(path ...Key)

func (*Tree[Key, Value]) Depth

func (tree *Tree[Key, Value]) Depth() int

func (*Tree[Key, Value]) Fetch

func (tree *Tree[Key, Value]) Fetch(path ...Key) (opt Optional[Value])

func (*Tree[Key, Value]) Get

func (tree *Tree[Key, Value]) Get(path ...Key) (depth int, opt Optional[Value])

func (*Tree[Key, Value]) GetTree

func (tree *Tree[Key, Value]) GetTree(path ...Key) *Tree[Key, Value]

func (*Tree[Key, Value]) Name

func (tree *Tree[Key, Value]) Name() Key

func (*Tree[Key, Value]) Path

func (tree *Tree[Key, Value]) Path() []Key

func (*Tree[Key, Value]) Range

func (tree *Tree[Key, Value]) Range(fn func(*Tree[Key, Value]) bool, path ...Key)

func (*Tree[Key, Value]) RangeAll

func (tree *Tree[Key, Value]) RangeAll(fn func(*Tree[Key, Value]) bool)

func (*Tree[Key, Value]) RangeLevel

func (tree *Tree[Key, Value]) RangeLevel(fn func(*Tree[Key, Value]) bool, level int)

func (*Tree[Key, Value]) RangeLimit

func (tree *Tree[Key, Value]) RangeLimit(fn func(*Tree[Key, Value]) bool, maxDepth int)

func (*Tree[Key, Value]) Set

func (tree *Tree[Key, Value]) Set(data Value, path ...Key)

func (*Tree[Key, Value]) SetRange

func (tree *Tree[Key, Value]) SetRange(data Value, lvl int)

func (*Tree[Key, Value]) Trees

func (tree *Tree[Key, Value]) Trees() []*Tree[Key, Value]

type Vec

type Vec[T any] []T

func MakeVec

func MakeVec[T any](elmnts ...T) Vec[T]

func MakeVecSize

func MakeVecSize[T any](size, capacity int) Vec[T]

func (*Vec[T]) Append

func (vc *Vec[T]) Append(elmnts ...T)

func (Vec[T]) Back

func (vc Vec[T]) Back() (opt OptionalPtr[T])

func (Vec[T]) Cap

func (vc Vec[T]) Cap() int

func (Vec[T]) Contains

func (vc Vec[T]) Contains(cmpFn CompareFunc[T]) bool

func (*Vec[T]) DelByIndex

func (vc *Vec[T]) DelByIndex(i int) (val T, erased bool)

func (*Vec[T]) Filter

func (vc *Vec[T]) Filter(cmpFn CompareFunc[T]) (val T, erased bool)

func (Vec[T]) Front

func (vc Vec[T]) Front() (opt OptionalPtr[T])

func (Vec[T]) Get

func (vc Vec[T]) Get(i int) T

func (Vec[T]) Index

func (vc Vec[T]) Index(cmpFn CompareFunc[T]) int

func (Vec[T]) Len

func (vc Vec[T]) Len() int

func (*Vec[T]) PopBack

func (vc *Vec[T]) PopBack() (opt OptionalPtr[T])

func (*Vec[T]) PopFront

func (vc *Vec[T]) PopFront() (opt OptionalPtr[T])

func (*Vec[T]) Push

func (vc *Vec[T]) Push(elmnts ...T)

func (*Vec[T]) Reserve

func (vc *Vec[T]) Reserve(n int)

func (*Vec[T]) Resize

func (vc *Vec[T]) Resize(n int)

func (Vec[T]) Search

func (vc Vec[T]) Search(cmpFn CompareFunc[T]) (v T, ok bool)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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