Documentation ¶
Overview ¶
Package zint implements functions for ints.
Index ¶
- func Contains(list []int, i int) booldeprecated
- func Contains64(list []int64, i int64) booldeprecated
- func Difference(set []int64, others ...[]int64) []int64deprecated
- func DivideCeil(count int64, pageSize int64) int64
- func Fields(s string) ([]int64, error)
- func Filter(list []int64, fun func(int64) bool) []int64
- func FilterEmpty(e int64) bool
- func Join[T integer](ints []T, sep string) string
- func Join64(ints []int64, sep string) stringdeprecated
- func Max[T integer](a, b T) T
- func MaxInt(a, b int) intdeprecated
- func Min[T integer](a, b T) T
- func MinInt(a, b int) intdeprecated
- func NonZero(a, b int64, c ...int64) int64
- func Range(start, end int) []int
- func RoundToPowerOf2(n uint64) uint64
- func Split(s string, sep string) ([]int64, error)
- func ToIntSlice(v any) ([]int64, bool)
- func ToUintSlice(v any) ([]uint64, bool)
- func Uniq(list []int64) []int64deprecated
- type Bitflag16
- type Bitflag32
- type Bitflag64
- type Bitflag8
- type Int
- type Uint128
- func (i Uint128) Bytes() []byte
- func (i Uint128) Format(base int) string
- func (i Uint128) IsZero() bool
- func (i Uint128) MarshalText() ([]byte, error)
- func (i *Uint128) New(b []byte) error
- func (i *Uint128) Parse(str string, base int) error
- func (i *Uint128) Scan(v any) error
- func (i Uint128) String() string
- func (i Uint128) UUID() string
- func (i *Uint128) UnmarshalText(v []byte) error
- func (i Uint128) Value() (driver.Value, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contains64
deprecated
func Difference
deprecated
func DivideCeil ¶
DivideCeil divides two integers and rounds up, rather than down (which is what happens when you do int64/int64).
func Filter ¶
Fiter a list.
The function will be called for every item and those that return false will not be included in the return value.
func FilterEmpty ¶
FilterEmpty is a filter for Filter() to remove empty entries.
func NonZero ¶
NonZero returns the first argument that is not 0. It will return 0 if all arguments are 0.
func RoundToPowerOf2 ¶
RoundToPowerOf2 rounds up to the nearest power of 2.
https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
func ToIntSlice ¶
ToIntSlice converts any []int type to an []int64.
func ToUintSlice ¶
ToUintSlice converts any []int type to an []uint64.
Types ¶
type Bitflag16 ¶
type Bitflag16 uint16
Bitflag16 is an uint16 with some extra methods to make bitmask/flag manipulation a bit more convenient.
func (*Bitflag16) UnmarshalJSON ¶
func (*Bitflag16) UnmarshalText ¶
type Bitflag32 ¶
type Bitflag32 uint32
Bitflag32 is an uint32 with some extra methods to make bitmask/flag manipulation a bit more convenient.
func (*Bitflag32) UnmarshalJSON ¶
func (*Bitflag32) UnmarshalText ¶
type Bitflag64 ¶
type Bitflag64 uint64
Bitflag64 is an uint64 with some extra methods to make bitmask/flag manipulation a bit more convenient.
func (*Bitflag64) UnmarshalJSON ¶
func (*Bitflag64) UnmarshalText ¶
type Bitflag8 ¶
type Bitflag8 uint8
Bitflag8 is an uint8 with some extra methods to make bitmask/flag manipulation a bit more convenient.
func (*Bitflag8) UnmarshalJSON ¶
func (*Bitflag8) UnmarshalText ¶
type Int ¶
type Int int
Int with various methods to make conversions easier; useful especially in templates etc.
type Uint128 ¶
type Uint128 [2]uint64
Uint128 is an unsigned 128-bit integer.
Mostly intended to store UUIDs; storing it as a []byte takes up 40 bytes, whereas storing it in two uint64s takes up 16 bytes.
It's stored in so-called "big endian" format; that is, the most significant bit is on the right.
func NewUint128 ¶
NewUint128 creates a new uint128 from a [16]byte.
func (Uint128) Format ¶
Format according to the given base.
TODO: this is not really printin a number, but just printing the 2 numbers side-by-side, rather than actually adding up the bits.
func (Uint128) MarshalText ¶
MarshalText converts the data to a human readable representation.
func (*Uint128) UnmarshalText ¶
UnmarshalText parses text in to the Go data structure.