ints

package
v0.0.0-...-86e9f11 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package ints provides int-related common functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlignDown

func AlignDown(v, alignment uint) uint

AlignDown returns v aligned down to a given alignment.

func AlignDown16

func AlignDown16(v, alignment uint16) uint16

AlignDown16 returns v aligned down to a given alignment.

func AlignDown32

func AlignDown32(v, alignment uint32) uint32

AlignDown32 returns v aligned down to a given alignment.

func AlignDown64

func AlignDown64(v, alignment uint64) uint64

AlignDown64 returns v aligned down to a given alignment.

func AlignDown8

func AlignDown8(v, alignment uint8) uint8

AlignDown8 returns v aligned down to a given alignment.

func AlignUp

func AlignUp(v, alignment uint) uint

AlignUp returns v aligned up to a given alignment.

func AlignUp16

func AlignUp16(v, alignment uint16) uint16

AlignUp16 returns v aligned up to a given alignment.

func AlignUp32

func AlignUp32(v, alignment uint32) uint32

AlignUp32 returns v aligned up to a given alignment.

func AlignUp64

func AlignUp64(v, alignment uint64) uint64

AlignUp64 returns v aligned up to a given alignment.

func AlignUp8

func AlignUp8(v, alignment uint8) uint8

AlignUp8 returns v aligned up 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 IsAligned

func IsAligned(v, alignment uint) bool

IsAligned returns true if and only if v is an integer multiple of alignment

func IsAligned16

func IsAligned16(v, alignment uint16) bool

IsAligned16 returns true if and only if v is an integer multiple of alignment

func IsAligned32

func IsAligned32(v, alignment uint32) bool

IsAligned32 returns true if and only if v is an integer multiple of alignment

func IsAligned64

func IsAligned64(v, alignment uint64) bool

IsAligned64 returns true if and only if v is an integer multiple of alignment

func IsAligned8

func IsAligned8(v, alignment uint8) bool

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

func (in Interval) Each(fn func(int))

Each calls [fn] for each value in the interval.

func (Interval) EachErr

func (in Interval) EachErr(fn func(int) error) error

EachErr calls [fn] for each value in the interval. If [fn] returns a non-nil error, this stops and returns the error.

func (Interval) Empty

func (in Interval) Empty() bool

Empty returns whether [in] is an empty interval.

func (Interval) Intersect

func (in Interval) Intersect(x Interval) Interval

Intersect returns the intersection of [in] and [x]. If there is no overlap, the returned interval is empty.

func (Interval) Len

func (in Interval) Len() int

Len returns the length of the interval.

func (*Interval) Next

func (in *Interval) Next() (int, bool)

Next removes and returns the first integer in the series. This returns (0, false) if [in] is empty.

type Intervals

type Intervals []Interval

Intervals represents a series of half-open intervals.

func (Intervals) Clone

func (in Intervals) Clone() Intervals

Clone returns a copy of [in].

func (*Intervals) Compress

func (in *Intervals) Compress()

Compress compresses [in] so that all the contained intervals are ordered and non-overlapping.

func (Intervals) Each

func (in Intervals) Each(fn func(n int))

Each calls [fn] for each value in the interval.

func (Intervals) EachErr

func (in Intervals) EachErr(fn func(n int) error) error

EachErr calls [fn] for each value in the interval. If [fn] returns a non-nil error, this stops and returns the error.

func (Intervals) Empty

func (in Intervals) Empty() bool

Empty returns whether all the intervals in [in] are empty.

func (Intervals) Intersect

func (in Intervals) Intersect(x Intervals) Intervals

Intersect returns the intersection of [in] and [x]. If there is no overlap, the returned interval is empty.

func (Intervals) Len

func (in Intervals) Len() int

Len returns the length of the intervals.

func (*Intervals) Next

func (in *Intervals) Next() (int, bool)

Next removes and returns the first integer in the series. This returns (0, false) if [in] is empty.

func (Intervals) Overlaps

func (in Intervals) Overlaps(start, end int) bool

Overlaps returns whether [in] overlaps with the half-open interval [start, end).

The behavior of Overlaps when start >= end is unspecified.

func (Intervals) Visit

func (in Intervals) Visit(fn func(start, end int))

Visit visits distinct (non-overlapping) intervals within [in].

If the intervals are empty, [fn] will be called once with (0, 0).

Jump to

Keyboard shortcuts

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