varint

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2022 License: MIT Imports: 11 Imported by: 0

README

varint

VarInt: fast & memory efficient arbitrary bit width integers in Go.

Introduction

VarInt Go library provides fast & memory efficient arbitrary bit width unsigned integer array type.

The purpose of VarInt to provide the maximum memory compact way to use and store unsigned custom bits integers. It does so by storing all the integers adjacent to each other inside a continuous numeric byte slice. It allocates the underlying numeric bytes slice only once on creation and doesn't expect to allocate any more memory afterwards. VarInt provides all the basic arithmetic and bitwise operations. To apply any of these operations, internal bits manipulations are required which implies certain computational overhead. Thus providing a tradeoff between CPU time and memory. Overhead grows lineraly, proportionally to bit len and is comparable with overhead from big.Int operations. Unlike big.Int however, VarInt uses exact number of bits to store the integers inside. Which makes VarInt extremely memory efficient. For example, to store a slice of 100 integers 100 bit each, big.Int requires 12400 bits, while VarInt needs exactly 10000 bits. In the same fashion VarInt also provides an efficient way to store integers smaller than 64 bits. For example, to store a slice of 1000 integers 2 bit each, []uin8 requires 8000 bits, while VarInt needs exactly 2000 bits. However, note that VarInt is no way close to be optimized as well as big.Int, and provides diminishing returns as bit length grows above certain threshold.

Currently, in a conscious decision multiple operations are implemented in favour of simplicity and not computational complexity, this includes Mul that uses standard long multiplication instead of fast multiplication algorithms like Karatsuba multiplication, and Div that uses standard slow division instead of fast division algorithms. The main rationale behind this choice is the fact that VarInt has the most efficiency when used for small and medium size integers in the range of 1 to 5000 bit width, therefore asymptotic complexity should be less significant for this library. Note that VarInt carries a small fixed overhead internaly, it allocates 2 separate uint cells at the beginning of the numeric bytes slice to store length and bit length. It also collocates extra Bits variable at the end of numeric bytes slice which is used internally for many operations as a computation temporary buffer, including: Mul, Div, Mod, Sort. Currently, for simplicity and consistency most VarInt operations apply changes in place on the provided index and require the provided Bits to have exactly the same bit len, otherwise ErrorUnequalBitLengthCardinality is returned. Currently, VarInt provides only unsigned arithmetic.

Examples

Allocate 10000 integers VarInt 25 bits in width. And then fills it with its max value.

vint, _ := varint.NewVarInt(25, 10000)
b := varint.NewBits(25, []uint{ 33554431 })
for i := 0; i < 10000; i++ {
    _ = vint.Set(i, b)
}

Allocate 10000 integers VarInt 25 bits in width. Fills it with increasing values, and rotates it right.

vint, _ := varint.NewVarInt(25, 10000)
for i := 0; i < 10000; i++ {
    _ = vint.Set(i, varint.NewBitsBits(25, varint.NewBitsUint(uint(i))))
}
b := varint.NewBits(25, nil)
_ = vint.Get(0, b)
for i := 1; i < 10000; i++ {
    _ = vint.GetSet(i, b)
}
_ = vint.Set(0, b)

Allocates 10000 integers VarInt 50 bits in width. Fills it with random values, then finds min and max values.

vint, _ := varint.NewVarInt(50, 10000)
rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
for i := 0; i < 10000; i++ {
    _ = vint.Set(i, varint.NewBitsRand(50, rnd))
}
bmin, bmax, b := varint.NewBits(50, nil), varint.NewBits(50, nil), varint.NewBits(50, nil)
_, _ = vint.Get(0, bmin), vint.Get(0, bmax)
for i := 1; i < 10000; i++ {
    _ = vint.Get(i, b)
    switch {
        case varint.Compare(b, bmin) == -1:
            bmin = varint.NewBitsBits(50, b)
        case varint.Compare(b, bmax) == 1:
            bmax = varint.NewBitsBits(50, b)
    }
}

Allocates 10000 integers VarInt 50 bits in width. Fills it from big.Int channel, then subtracts 1000 from even numbers and adds 1 to odd numbers. Finally, converts integers back to the big.Int channel.

ch := make(chan *big.Int)
vint, _ := varint.NewVarInt(50, 10000)
for i := 0; i < 10000; i++ {
    _ = vint.Set(i, varint.NewBitsBits(50, varint.NewBitsBigInt(<-ch)))
}
b1000, b1 := varint.NewBitsBits(50, varint.NewBitsUint(1000)), varint.NewBitsBits(50, varint.NewBitsUint(1))
for i := 0; i < 10000; i++ {
    if i % 2 == 0 {
        _ = vint.Sub(i, b1000)
    } else {
        _ = vint.Add(i, b1)
    }
}
for i := 0; i < 10000; i++ {
    _ = vint.Get(i, b1)
    ch <- b1.BigInt()
}

Allocates 10000 integers VarInt 50 bits in width. Fills it with random values, then if bitwise negation for a number is even multiply it by 2.

vint, _ := varint.NewVarInt(50, 10000)
rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
for i := 0; i < 10000; i++ {
    _ = vint.Set(i, varint.NewBitsRand(50, rnd))
}
b, b2 := varint.NewBits(50, nil), varint.NewBitsBits(50, varint.NewBitsUint(2))
for i := 0; i < 10000; i++ {
    _ = vint.Get(i, b)
    _ = vint.Not(i)
    _ = vint.Mod(i, b2)
    _ = vint.GetSet(i, b)
    if b.Empty() {
        _ = vint.Mul(i, b2)
    }
}

Allocates 10000 integers VarInt 100 bits in width. Fills it with random values, then sorts it in ascending order.

vint, _ := varint.NewVarInt(100, 10000)
rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
for i := 0; i < 10000; i++ {
    _ = vint.Set(i, varint.NewBitsRand(100, rnd))
}
sort.Sort(varint.Sortable(vint))

Allocates 10000 integers VarInt 100 bits in width. Fills it with random values, then flushes it to a file and reads it back.

vint, _ := varint.NewVarInt(100, 10000)
rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
for i := 0; i < 10000; i++ {
    _ = vint.Set(i, varint.NewBitsRand(100, rnd))
}
f, _ := os.Create("vint.bin")
defer os.Remove(f.Name())
_, _ = f.ReadFrom(varint.Encode(vint))
f, _ = os.Open(f.Name())
_ = varint.Decode(f, vint)

Benchmarks

Arithmetic Operations 100000000 integers, 4 bits width

ns/op B/op allocs/op allocs/MB
VarInt 103.3 0 0 47.69
Uint8 Slice 1.555 0 0 95.38

Arithmetic Operations 10000000 integers, 64 bits width

ns/op B/op allocs/op allocs/MB
VarInt 99.46 0 0 76.30
Uint64 Slice 2.398 0 0 76.30

Arithmetic Operations 10000000 integers, 100 bits width

ns/op B/op allocs/op allocs/MB
VarInt 169.4 0 0 119.2
BigInt Slice 504.9 120 3 495.9

Arithmetic Operations 100000 integers, 10000 bits width

ns/op B/op allocs/op allocs/MB
VarInt 78451 0 0 119.2
BigInt Slice 657.8 .0 148 2 145.8

Bitwise Operations 100000000 integers, 4 bits width

ns/op B/op allocs/op allocs/MB
VarInt 76.84 0 0 47.69
Uint8 Slice 2.42 0 0 95.38

Arithmetic Operations 10000000 integers, 64 bits width

ns/op B/op allocs/op allocs/MB
VarInt 79.06 0 0 76.30
Uint64 Slice 2.451 0 0 76.30

Arithmetic Operations 10000000 integers, 100 bits width

ns/op B/op allocs/op allocs/MB
VarInt 134.5 0 0 119.2
BigInt Slice 186.9 48 1 427.2

Arithmetic Operations 100000 integers, 10000 bits width

ns/op B/op allocs/op allocs/MB
VarInt 5273 0 0 119.2
BigInt Slice 172.3 153 0 150.3

The benchmarks from above are run using, see BenchmarkVarIntOperations for more details.

go version go1.19.3 darwin/amd64
Intel(R) Core(TM) i5-1030NG7 CPU @ 1.10GHz
go test -run=^$ -bench ^BenchmarkVarIntOperations$ github.com/1pkg/varint -benchtime 1000000x

Licence

VarInt is licensed under the MIT License.
See LICENSE for the full license text.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorBitLengthIsNotPositive      = errors.New("the provided bit length has to be a strictly positive number")
	ErrorLengthIsNotPositive         = errors.New("the provided length has to be a strictly positive number")
	ErrorBitLengthIsNotEfficient     = errors.New("the provided bit length is over the threshold, for efficiency consider decreasing it or use big.Int slice")
	ErrorLengthIsNotEfficient        = errors.New("the provided length is under the threshold, for efficiency consider increasing it or use uint slice")
	ErrorVarIntIsInvalid             = errors.New("the varint is not valid for this operation")
	ErrorIndexIsNegative             = errors.New("the provided index has to be not be a negative number")
	ErrorIndexIsOutOfRange           = errors.New("the provided index is out of the number range")
	ErrorUnequalBitLengthCardinality = errors.New("the provided bit length does not have equal cardinality with the number")
	ErrorAdditionOverflow            = errors.New("the addition result overflows its max value")
	ErrorMultiplicationOverflow      = errors.New("the multiplication result overflows its max value")
	ErrorSubtractionUnderflow        = errors.New("the subtraction result underflow its min value")
	ErrorDivisionByZero              = errors.New("the division result is undefined for 0 value divisor")
	ErrorReaderIsNotDecodable        = errors.New("reader does not contain decodable bytes")
	ErrorShiftIsNegative             = errors.New("the provided shift has to be not be a negative number")
)

The register of all static errors and warns that can be returned by VarInt.

Functions

func BitLen

func BitLen(vint VarInt) int

BitLen returns bit length of the VarInt instance. BitLen is standalone function by choice to make VarInt more consistent and ergonomic. It's safe to use on nil VarInt, 0 is returned.

func Compare

func Compare(abits, bbits Bits) int

Compare returns an integer comparing of the provided Bits. The result is 0 if Bits a == b, -1 if Bits a < b, and +1 Bits if a > b. Currently it only compare bits with the same bit len akin to VarInt operations.

func Decode

func Decode(r io.ReadCloser, vint VarInt) error

Decode dencodes the io.ReadCloser result from Encode into the provided VarInt. The provided VarInt has to be already preallocated, otherwise the ErrorVarIntIsInvalid is returned. The provided io.ReadCloser has to be encoded with binary.BigEndian iside, otherwise the ErrorReaderIsNotDecodable is returned.

func Encode

func Encode(vint VarInt) io.ReadCloser

Encode lazily encodes the provided VarInt into io.ReadCloser. It uses binary.BigEndian encoding for the number. It also starts a goroutine to encode the number lazily, so the returned io.ReadCloser has to be always closed otherwise goroutine leak occures.

func Len

func Len(vint VarInt) int

Len returns length of the VarInt instance. Len is standalone function by choice to make VarInt more consistent and ergonomic. It's safe to use on nil VarInt, 0 is returned.

func Sortable

func Sortable(vint VarInt) sort.Interface

Sortable returns sort.Interface adapter for provided VarInt that is capable to work with standard sort package.

Types

type Bits

type Bits []uint

Bits is immutable intermediate representation for single integer inside VarInt. It's used as data transfer object for most of VarInt operations, and provides a number of convenient methods to convert it back and forth between other numerical presentations. Bits type somewhat resembles unsigned big.Int internally and provides similar transformations. However, note that by design most of Bits operations are not fast and allocate memory therefore should be only used to bootstrap and pass data to VarIant and not as standalone type.

func NewBits

func NewBits(blen int, bytes []uint) Bits

NewBits allocates and returns new Bits instance with predefined bit length and optional initialization value bytes slice. In case value bytes slice doesn't fit into the provided bit length, it is truncated to fit into the provided bit len. In case the provided bit len is negative number, actual bit len is calculated from the bytes slice. In case the provided bit len is 0, empty Bits marker is returned. See Bits type for more details.

func NewBitsBigInt

func NewBitsBigInt(i *big.Int) Bits

NewBitsBigInt allocates, copies and returns new Bits instance from the provided big.Int, it deduces bit length to exactly fit the provided number. In case nil is provided empty Bits marker is returned. See Bits type for more details.

func NewBitsBits

func NewBitsBits(blen int, bits Bits) Bits

NewBitsBits allocates, copies and returns new Bits instance from the provided bit len and Bits, effectively making a deep copy of it. See Bits type for more details.

func NewBitsRand

func NewBitsRand(blen int, rnd *rand.Rand) Bits

NewBitsRand allocates and returns new Bits instance filled with random bytes from provided Rand that fits the provided bit length. See Bits type for more details.

func NewBitsString

func NewBitsString(s string, base int) Bits

NewBitsString parses, allocates and returns new Bits instance from the provided string and base, it deduces bit length to exactly fit the provided number. Valid base values are inside [2, 62], base values below 2 are converted to 2, base values above 62 are converted to 62. Leading plus '+' sings are ignored. Separating underscore '_' signs are allowed and also ignored. In case empty or invalid string is provided a special nil Bits marker is returned. The implementation follows big.Int. See Bits type for more details.

func NewBitsUint

func NewBitsUint(n uint) Bits

NewBitsUint allocates and returns new Bits instance with deduced bit length to exactly fit the provided number. See Bits type for more details.

func (Bits) BigInt

func (bits Bits) BigInt() *big.Int

BigInt allocates and returns a big.Int from value bytes slice of the Bits instance. It's safe to use on nil Bits, 0 is returned.

func (Bits) BitLen

func (bits Bits) BitLen() int

BitLen returns bit length of the Bits instance. It's safe to use on nil Bits, 0 is returned.

func (Bits) Bytes

func (bits Bits) Bytes() []uint

Bytes returns value bytes slice of the Bits instance. It's safe to use on nil Bits, {0} is returned.

func (Bits) Empty

func (bits Bits) Empty() bool

Empty returns true on nil Bits, or if the bit length is 0 or if value bytes slice is empty, otherwise returns false.

func (Bits) Format

func (bits Bits) Format(f fmt.State, verb rune)

Format formats the Bits instance accordingly to provided format, most numeric formats are supported as well as #, 0 flags and pad width flag. In case invalid format is provided nothing is returned. It's safe to use on nil Bits, empty value is returned. Implements fmt.Formatter. The implementation follows big.Int.

func (Bits) String

func (bits Bits) String() string

String returns a hex '%#X' string representation of the Bits instance decorated with bit length, in format '[blen]{hex_bytes}'. It's safe to use on nil Bits, [0]{0x0} is returned. Implements fmt.Stringer.

func (Bits) To

func (bits Bits) To(base int) []byte

To allocates and returns []byte representation of the Bits instance using the provided base. Valid base values are inside [2, 62], base values below 2 are converted to 2, base values above 62 are converted to 62. It's safe to use on nil Bits, {'0'} is returned. The implementation follows big.Int.

func (Bits) Uint

func (bits Bits) Uint() uint

Uint returns the low word from value bytes slice of the Bits instance. It's safe to use on nil Bits, 0 is returned.

type VarInt

type VarInt []uint

VarInt provides fast and memory efficient arbitrary bit length unsigned integer array type.

The purpose of VarInt to provide the maximum memory compact way to use and store unsigned custom bits integers. It does so by storing all the integers adjacent to each other inside a continuous numeric byte slice. It allocates the underlying numeric bytes slice only once on creation and doesn't expect to allocate any more memory afterwards. VarInt provides all the basic arithmetic and bitwise operations. To apply any of these operations, internal bits manipulations are required which implies certain computational overhead. Thus providing a tradeoff between CPU time and memory. Overhead grows lineraly, proportionally to bit len and is comparable with overhead from big.Int operations. Unlike big.Int however, VarInt uses exact number of bits to store the integers inside. Which makes VarInt extremely memory efficient. For example, to store a slice of 100 integers 100 bit each, big.Int requires 12400 bits, while VarInt needs exactly 10000 bits. In the same fashion VarInt also provides an efficient way to store integers smaller than 64 bits. For example, to store a slice of 1000 integers 2 bit each, []uin8 requires 8000 bits, while VarInt needs exactly 2000 bits. However, note that VarInt is no way close to be optimized as well as big.Int, and provides diminishing returns as bit length grows above certain threshold.

Currently, in a conscious decision multiple operations are implemented in favour of simplicity and not computational complexity, this includes Mul that uses standard long multiplication instead of fast multiplication algorithms like Karatsuba multiplication, and Div that uses standard slow division instead of fast division algorithms. The main rationale behind this choice is the fact that VarInt has the most efficiency when used for small and medium size integers in the range of 1 to 5000 bit width, therefore asymptotic complexity should be less significant for this library. Note that VarInt carries a small fixed overhead internaly, it allocates 2 separate uint cells at the beginning of the numeric bytes slice to store length and bit length. It also collocates extra Bits variable at the end of numeric bytes slice which is used internally for many operations as a computation temporary buffer, including: Mul, Div, Mod, Sort. Currently, for simplicity and consistency most VarInt operations apply changes in place on the provided index and require the provided Bits to have exactly the same bit len, otherwise ErrorUnequalBitLengthCardinality is returned. Currently, VarInt provides only unsigned arithmetic.

func NewVarInt

func NewVarInt(blen, len int) (VarInt, error)

NewVarInt allocates and returns VarInt instance that is capable to fit the provided number of integers each of the provided bit len in width. In case the provided bit len is not positive, invalid number and ErrorBitLengthIsNotPositive is returned. In case the len is not positive, invalid number and ErrorLengthIsNotPositive is returned. In case the provided bit len is larger than predefined threshold of 4096, valid VarInt is still returned along with ErrorBitLengthIsNotEfficient warning. In case the provided len is smaller than predefined threshold of 4, valid VarInt is still returned along with ErrorLengthIsNotEfficient warning. See VarInt type for more details.

func (VarInt) Add

func (vint VarInt) Add(i int, bits Bits) error

Add adds the provided bits to the integer inside VarInt at the provided index. In case the operation is used on invalid nil VarInt, ErrorVarIntIsInvalid is returned. In case negative index is provided, ErrorIndexIsNegative is returned. In case the provided index is greater than len of VarInt, ErrorIndexIsOutOfRange is returned. In case the provided bits has different bit len, ErrorUnequalBitLengthCardinality is returned. In case the addition result overflows the bit len, the regular unsigned semantic applies and extra ErrorAdditionOverflow warning is returned.

func (VarInt) And

func (vint VarInt) And(i int, bits Bits) error

And applies bitwise and & operation to the provided bits and the integer inside VarInt at the provided index. In case the operation is used on invalid nil VarInt, ErrorVarIntIsInvalid is returned. In case negative index is provided, ErrorIndexIsNegative is returned. In case the provided index is greater than len of VarInt, ErrorIndexIsOutOfRange is returned. In case the provided bits has different bit len, ErrorUnequalBitLengthCardinality is returned.

func (VarInt) Div

func (vint VarInt) Div(i int, bits Bits) error

Div divides the provided bits with the integer inside VarInt at the provided index. In case the operation is used on invalid nil VarInt, ErrorVarIntIsInvalid is returned. In case negative index is provided, ErrorIndexIsNegative is returned. In case the provided index is greater than len of VarInt, ErrorIndexIsOutOfRange is returned. In case the provided bits has different bit len, ErrorUnequalBitLengthCardinality is returned. In case the division by zero is attempted, ErrorDivisionByZero is returned

func (VarInt) Get

func (vint VarInt) Get(i int, bits Bits) error

Get sets the provided bits to the integer inside VarInt at the provided index. It never allocates new Bits, the provided Bits are expected to be preallocated by the caller. In case the operation is used on invalid nil VarInt, ErrorVarIntIsInvalid is returned. In case negative index is provided, ErrorIndexIsNegative is returned. In case the provided index is greater than len of VarInt, ErrorIndexIsOutOfRange is returned. In case the provided bits has different bit len, ErrorUnequalBitLengthCardinality is returned.

func (VarInt) GetSet

func (vint VarInt) GetSet(i int, bits Bits) error

GetSet swaps the provided bits with the integer inside VarInt at the provided index. In case the operation is used on invalid nil VarInt, ErrorVarIntIsInvalid is returned. In case negative index is provided, ErrorIndexIsNegative is returned. In case the provided index is greater than len of VarInt, ErrorIndexIsOutOfRange is returned. In case the provided bits has different bit len, ErrorUnequalBitLengthCardinality is returned.

func (VarInt) Lsh

func (vint VarInt) Lsh(i, n int) error

Lsh applies left shift << operation to the integer inside VarInt at the provided index. In case the operation is used on invalid nil VarInt, ErrorVarIntIsInvalid is returned. In case negative shift is provided, ErrorShiftIsNegative is returned. In case negative index is provided, ErrorIndexIsNegative is returned. In case the provided index is greater than len of VarInt, ErrorIndexIsOutOfRange is returned.

func (VarInt) Mod

func (vint VarInt) Mod(i int, bits Bits) error

Mod applies modulo operation to the provided bits and the integer inside VarInt at the provided index. In case the operation is used on invalid nil VarInt, ErrorVarIntIsInvalid is returned. In case negative index is provided, ErrorIndexIsNegative is returned. In case the provided index is greater than len of VarInt, ErrorIndexIsOutOfRange is returned. In case the provided bits has different bit len, ErrorUnequalBitLengthCardinality is returned. In case the division by zero is attempted, ErrorDivisionByZero is returned

func (VarInt) Mul

func (vint VarInt) Mul(i int, bits Bits) error

Mul multiplies the provided bits with the integer inside VarInt at the provided index. In case the operation is used on invalid nil VarInt, ErrorVarIntIsInvalid is returned. In case negative index is provided, ErrorIndexIsNegative is returned. In case the provided index is greater than len of VarInt, ErrorIndexIsOutOfRange is returned. In case the provided bits has different bit len, ErrorUnequalBitLengthCardinality is returned. In case the multiplication result overflows the bit len, the integer is trucated and extra ErrorMultiplicationOverflow warning is returned.

func (VarInt) Not

func (vint VarInt) Not(i int) error

Not applies bitwise negation ^ operation to the integer inside VarInt at the provided index. In case the operation is used on invalid nil VarInt, ErrorVarIntIsInvalid is returned. In case negative index is provided, ErrorIndexIsNegative is returned. In case the provided index is greater than len of VarInt, ErrorIndexIsOutOfRange is returned.

func (VarInt) Or

func (vint VarInt) Or(i int, bits Bits) error

Or applies bitwise and | operation to the provided bits and the integer inside VarInt at the provided index. In case the operation is used on invalid nil VarInt, ErrorVarIntIsInvalid is returned. In case negative index is provided, ErrorIndexIsNegative is returned. In case the provided index is greater than len of VarInt, ErrorIndexIsOutOfRange is returned. In case the provided bits has different bit len, ErrorUnequalBitLengthCardinality is returned.

func (VarInt) Rsh

func (vint VarInt) Rsh(i, n int) error

Rsh applies right shift >> operation to the integer inside VarInt at the provided index. In case the operation is used on invalid nil VarInt, ErrorVarIntIsInvalid is returned. In case negative shift is provided, ErrorShiftIsNegative is returned. In case negative index is provided, ErrorIndexIsNegative is returned. In case the provided index is greater than len of VarInt, ErrorIndexIsOutOfRange is returned.

func (VarInt) Set

func (vint VarInt) Set(i int, bits Bits) error

Set sets the provided bits into the integer inside VarInt at the provided index. In case the operation is used on invalid nil VarInt, ErrorVarIntIsInvalid is returned. In case negative index is provided, ErrorIndexIsNegative is returned. In case the provided index is greater than len of VarInt, ErrorIndexIsOutOfRange is returned. In case the provided bits has different bit len, ErrorUnequalBitLengthCardinality is returned.

func (VarInt) Sub

func (vint VarInt) Sub(i int, bits Bits) error

Sub subtracts the provided bits from the integer inside VarInt at the provided index. In case the operation is used on invalid nil VarInt, ErrorVarIntIsInvalid is returned. In case negative index is provided, ErrorIndexIsNegative is returned. In case the provided index is greater than len of VarInt, ErrorIndexIsOutOfRange is returned. In case the provided bits has different bit len, ErrorUnequalBitLengthCardinality is returned. In case the subtraction result underflows the integer, the regular unsigned semantic applies and extra ErrorSubtractionUnderflow warning is returned.

func (VarInt) Xor

func (vint VarInt) Xor(i int, bits Bits) error

Xor applies bitwise and ^ operation to the provided bits and the integer inside VarInt at the provided index. In case the operation is used on invalid nil VarInt, ErrorVarIntIsInvalid is returned. In case negative index is provided, ErrorIndexIsNegative is returned. In case the provided index is greater than len of VarInt, ErrorIndexIsOutOfRange is returned. In case the provided bits has different bit len, ErrorUnequalBitLengthCardinality is returned.

Jump to

Keyboard shortcuts

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