Documentation ¶
Overview ¶
Package zint implements functions for ints.
Index ¶
- func DivideCeil(count int64, pageSize int64) int64
- func Fields(s string) ([]int64, error)
- func Join[T integer](ints []T, sep string) string
- 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)
- 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 DivideCeil ¶
DivideCeil divides two integers and rounds up, rather than down (which is what happens when you do int64/int64).
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.