zint

package
v0.0.0-...-49fafbb Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: MIT Imports: 5 Imported by: 11

Documentation

Overview

Package zint implements functions for ints.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DivideCeil

func DivideCeil(count int64, pageSize int64) int64

DivideCeil divides two integers and rounds up, rather than down (which is what happens when you do int64/int64).

func Fields

func Fields(s string) ([]int64, error)

Fields splits a strings with strings.Fields() and parses each entry as an integer.

func Join

func Join[T integer](ints []T, sep string) string

Join a slice of ints to a comma separated string with the given separator.

func Range

func Range(start, end int) []int

Range creates an []int counting at "start" up to (and including) "end".

func RoundToPowerOf2

func RoundToPowerOf2(n uint64) uint64

RoundToPowerOf2 rounds up to the nearest power of 2.

https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2

func Split

func Split(s string, sep string) ([]int64, error)

Split a string to a slice of []int64.

func ToIntSlice

func ToIntSlice(v any) ([]int64, bool)

ToIntSlice converts any []int type to an []int64.

func ToUintSlice

func ToUintSlice(v any) ([]uint64, bool)

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) Clear

func (f *Bitflag16) Clear(flag Bitflag16)

func (Bitflag16) Has

func (f Bitflag16) Has(flag Bitflag16) bool

func (*Bitflag16) Set

func (f *Bitflag16) Set(flag Bitflag16)

func (*Bitflag16) Toggle

func (f *Bitflag16) Toggle(flag Bitflag16)

func (*Bitflag16) UnmarshalJSON

func (f *Bitflag16) UnmarshalJSON(text []byte) error

func (*Bitflag16) UnmarshalText

func (f *Bitflag16) UnmarshalText(text []byte) error

type Bitflag32

type Bitflag32 uint32

Bitflag32 is an uint32 with some extra methods to make bitmask/flag manipulation a bit more convenient.

func (*Bitflag32) Clear

func (f *Bitflag32) Clear(flag Bitflag32)

func (Bitflag32) Has

func (f Bitflag32) Has(flag Bitflag32) bool

func (*Bitflag32) Set

func (f *Bitflag32) Set(flag Bitflag32)

func (*Bitflag32) Toggle

func (f *Bitflag32) Toggle(flag Bitflag32)

func (*Bitflag32) UnmarshalJSON

func (f *Bitflag32) UnmarshalJSON(text []byte) error

func (*Bitflag32) UnmarshalText

func (f *Bitflag32) UnmarshalText(text []byte) error

type Bitflag64

type Bitflag64 uint64

Bitflag64 is an uint64 with some extra methods to make bitmask/flag manipulation a bit more convenient.

func (*Bitflag64) Clear

func (f *Bitflag64) Clear(flag Bitflag64)

func (Bitflag64) Has

func (f Bitflag64) Has(flag Bitflag64) bool

func (*Bitflag64) Set

func (f *Bitflag64) Set(flag Bitflag64)

func (*Bitflag64) Toggle

func (f *Bitflag64) Toggle(flag Bitflag64)

func (*Bitflag64) UnmarshalJSON

func (f *Bitflag64) UnmarshalJSON(text []byte) error

func (*Bitflag64) UnmarshalText

func (f *Bitflag64) UnmarshalText(text []byte) error

type Bitflag8

type Bitflag8 uint8

Bitflag8 is an uint8 with some extra methods to make bitmask/flag manipulation a bit more convenient.

func (*Bitflag8) Clear

func (f *Bitflag8) Clear(flag Bitflag8)

func (Bitflag8) Has

func (f Bitflag8) Has(flag Bitflag8) bool

func (*Bitflag8) Set

func (f *Bitflag8) Set(flag Bitflag8)

func (*Bitflag8) Toggle

func (f *Bitflag8) Toggle(flag Bitflag8)

func (*Bitflag8) UnmarshalJSON

func (f *Bitflag8) UnmarshalJSON(text []byte) error

func (*Bitflag8) UnmarshalText

func (f *Bitflag8) UnmarshalText(text []byte) error

type Int

type Int int

Int with various methods to make conversions easier; useful especially in templates etc.

func (Int) Float32

func (s Int) Float32() float32

func (Int) Float64

func (s Int) Float64() float64

func (Int) Int

func (s Int) Int() int

func (Int) Int64

func (s Int) Int64() int64

func (Int) String

func (s Int) String() string

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

func NewUint128(b []byte) (Uint128, error)

NewUint128 creates a new uint128 from a [16]byte.

func ParseUint128

func ParseUint128(s string, base int) (Uint128, error)

func (Uint128) Bytes

func (i Uint128) Bytes() []byte

func (Uint128) Format

func (i Uint128) Format(base int) string

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) IsZero

func (i Uint128) IsZero() bool

func (Uint128) MarshalText

func (i Uint128) MarshalText() ([]byte, error)

MarshalText converts the data to a human readable representation.

func (*Uint128) New

func (i *Uint128) New(b []byte) error

New sets this uint128 from a [16]byte.

func (*Uint128) Parse

func (i *Uint128) Parse(str string, base int) error

func (*Uint128) Scan

func (i *Uint128) Scan(v any) error

Scan converts the data from the DB.

func (Uint128) String

func (i Uint128) String() string

func (Uint128) UUID

func (i Uint128) UUID() string

UUID formats as a UUID.

func (*Uint128) UnmarshalText

func (i *Uint128) UnmarshalText(v []byte) error

UnmarshalText parses text in to the Go data structure.

func (Uint128) Value

func (i Uint128) Value() (driver.Value, error)

Value determines what to store in the DB.

Jump to

Keyboard shortcuts

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