Documentation
¶
Overview ¶
Package sixb provides string, slice & integer utility functions. string/slice functions help avoid redundant memory allocations.
Index ¶
- func AnumToSixb(alphanum byte) byte
- func Bytes[T ~string](str T) []byte
- func Copy[S ~[]T, T any](slc S) S
- func Dec(ctr *uint32) (new uint32)
- func Inc(ctr *uint32, max uint32) (new uint32)
- func InsideTest() bool
- func Integers[U Integer, T ~string](str T) []U
- func Mean[T Integer](x, y T) T
- func MeanS[T ~string](s1, s2 T) T
- func Median3[T cmp.Ordered](a, b, c T) T
- func Median4[T Integer](a, b, c, d T) T
- func PtrToInt[P ~*T, T any](ptr P) uint
- func SamePtr[P1 ~*T, P2 ~*U, T, U any](a P1, b P2) bool
- func SixbToAnum(sixb byte) byte
- func Slice[U any, S ~[]T, T any](slc S) []U
- func String[S ~[]T, T Integer](slc S) string
- type CircleQ
- type Float
- type Integer
- type None
- type Set
- type Signed
- type Unsigned
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnumToSixb ¶
AnumToSixb is a bijection (without fixed points, single cycle and inverse of SixbToAnum) that maps 0-9: @A-Z a-z onto 6-bits.
func Dec ¶
Dec attempts to decrement a counter with:
if ctr == nil || *ctr == 0 {
return ^0 // -1
}
atomic {
*ctr--
return *ctr
}
func Inc ¶
Inc attempts to increment a counter with:
if ctr == nil || *ctr >= max {
return 0
}
atomic {
*ctr++
return *ctr
}
func Mean ¶
func Mean[T Integer](x, y T) T
Mean returns average of integers x and y, mathematically equivalent to floor((x+y)/2). This function works on the whole domain of (x,y) pairs, unlike (x+y)/2.
func MeanS ¶
func MeanS[T ~string](s1, s2 T) T
MeanS returns lexicographic average of s1 and s2. It treats ascii specially. The result is (len(s1)+len(s2)+1)/2 bytes and may contain unprintable characters or may not be valid utf8.
func SixbToAnum ¶
SixbToAnum is a bijection (without fixed points, single cycle and inverse of AnumToSixb) that maps 6-bits onto 0-9: @A-Z a-z.
Types ¶
type CircleQ ¶
type CircleQ[T any] struct { // contains filtered or unexported fields }
CircleQ is a circular, fifo queue of items of type T with a maximum capacity. Create a new one like:
// It has four distinct states: var q CircleQ[int] // null : Push & Pop wont work q.Reset(2) // empty : Only Push will work q.Push(45) // partial: Push & Pop will work q.Push(46) // full : Only Pop will work item, ok := q.Pop() // returns 45, true r := NewCircleQ[int](2) // same as Reset
func NewCircleQ ¶
NewCircleQ creates a circular, fifo queue of given maximum capacity.
type Set ¶
type Set[K comparable] map[K]None
Set of elements of type K. Create empty set with
s := Set[K]{}
func (Set[K]) HasAll ¶
HasAll returns true only if set contains all of given elements. If els is empty, it returns true by definition.