Documentation ¶
Overview ¶
Package ints provides int-related common functions.
Index ¶
- func AlignDown(v, alignment uint) uint
- func AlignDown16(v, alignment uint16) uint16
- func AlignDown32(v, alignment uint32) uint32
- func AlignDown64(v, alignment uint64) uint64
- func AlignDown8(v, alignment uint8) uint8
- func AlignUp(v, alignment uint) uint
- func AlignUp16(v, alignment uint16) uint16
- func AlignUp32(v, alignment uint32) uint32
- func AlignUp64(v, alignment uint64) uint64
- func AlignUp8(v, alignment uint8) uint8
- func BoolTo[T constraints.Integer](v bool) T
- func ChunkCount[T constraints.Unsigned](n, chunkSize T) T
- func ClearBit[T, K constraints.Integer](in []T, k K)
- func ClearBits[T, K constraints.Integer](in []T, first, last K)
- func FlipBit[T, K constraints.Integer](in []T, k K)
- func FlipBits[T, K constraints.Integer](in []T, first, last K)
- func IsAligned(v, alignment uint) bool
- func IsAligned16(v, alignment uint16) bool
- func IsAligned32(v, alignment uint32) bool
- func IsAligned64(v, alignment uint64) bool
- func IsAligned8(v, alignment uint8) bool
- func RandomFillSlice[T constraints.Integer](out []T) error
- func SetBit[T, K constraints.Integer](in []T, k K)
- func SetBits[T, K constraints.Integer](in []T, first, last K)
- func TestBit[T, K constraints.Integer](in []T, k K) bool
- type Interval
- type Intervals
- func (in Intervals) Clone() Intervals
- func (in *Intervals) Compress()
- func (in Intervals) Each(fn func(n int))
- func (in Intervals) EachErr(fn func(n int) error) error
- func (in Intervals) Empty() bool
- func (in Intervals) Intersect(x Intervals) Intervals
- func (in Intervals) Len() int
- func (in *Intervals) Next() (int, bool)
- func (in Intervals) Overlaps(start, end int) bool
- func (in Intervals) Visit(fn func(start, end int))
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AlignDown16 ¶
AlignDown16 returns v aligned down to a given alignment.
func AlignDown32 ¶
AlignDown32 returns v aligned down to a given alignment.
func AlignDown64 ¶
AlignDown64 returns v aligned down to a given alignment.
func AlignDown8 ¶
AlignDown8 returns v aligned down to a given alignment.
func BoolTo ¶
func BoolTo[T constraints.Integer](v bool) T
BoolTo maps v into T{0, 1}, because T(v) can't...
func ChunkCount ¶
func ChunkCount[T constraints.Unsigned](n, chunkSize T) T
ChunkCount returns the number of chunkSize-bit chunks needed to store n bits
func ClearBit ¶
func ClearBit[T, K constraints.Integer](in []T, k K)
ClearBit clears the k-th bit in range "in"
func ClearBits ¶
func ClearBits[T, K constraints.Integer](in []T, first, last K)
ClearBits clears the bits [first, last) in range "in"
func FlipBit ¶
func FlipBit[T, K constraints.Integer](in []T, k K)
FlipBit inverts the k-th bit in range "in"
func FlipBits ¶
func FlipBits[T, K constraints.Integer](in []T, first, last K)
FlipBits inverts the bits [first, last) in range "in"
func IsAligned16 ¶
IsAligned16 returns true if and only if v is an integer multiple of alignment
func IsAligned32 ¶
IsAligned32 returns true if and only if v is an integer multiple of alignment
func IsAligned64 ¶
IsAligned64 returns true if and only if v is an integer multiple of alignment
func IsAligned8 ¶
IsAligned8 returns true if and only if v is an integer multiple of alignment
func RandomFillSlice ¶
func RandomFillSlice[T constraints.Integer](out []T) error
RandomFillSlice fills a slice of []T with content produced by a cryptographically strong random number generator
func SetBit ¶
func SetBit[T, K constraints.Integer](in []T, k K)
SetBit sets the k-th bit in range "in"
func SetBits ¶
func SetBits[T, K constraints.Integer](in []T, first, last K)
SetBits sets the bits [first, last) in range "in"
func TestBit ¶
func TestBit[T, K constraints.Integer](in []T, k K) bool
TestBit check if the k-th bit is set in range "in"
Types ¶
type Interval ¶
type Interval struct {
Start, End int
}
Interval is a half-open interval [start, end) (start is always less than or equal to end)
func (Interval) EachErr ¶
EachErr calls [fn] for each value in the interval. If [fn] returns a non-nil error, this stops and returns the error.
type Intervals ¶
type Intervals []Interval
Intervals represents a series of half-open intervals.
func (*Intervals) Compress ¶
func (in *Intervals) Compress()
Compress compresses [in] so that all the contained intervals are ordered and non-overlapping.
func (Intervals) EachErr ¶
EachErr calls [fn] for each value in the interval. If [fn] returns a non-nil error, this stops and returns the error.
func (Intervals) Intersect ¶
Intersect returns the intersection of [in] and [x]. If there is no overlap, the returned interval is empty.
func (*Intervals) Next ¶
Next removes and returns the first integer in the series. This returns (0, false) if [in] is empty.