@@ -5,30 +5,30 @@ import math_bits "math/bits"
55// wsize const alias to system uint word size in bits.
66const wsize = math_bits .UintSize
77
8- // VarInt defines the memory efficient unsigned numeric array type that provides
9- // basic arithmetic and bitwise operations on variadic bit length numbers. The purpose
10- // of VarInt to provide the memory optimal way to use unsigned custom bit len numbers .
11- // It does so by storing all the numbers adjacent to each other inside
8+ // VarInt defines the memory efficient unsigned integer array type that provides
9+ // basic arithmetic and bitwise operations on arbitrary variadic bit length integers.
10+ // The purpose of VarInt to provide the memory optimal way to use unsigned custom bit len integers .
11+ // It does so by storing all the integers adjacent to each other inside
1212// continuous numeric bytes slice. To function, it allocates the underlying
1313// numeric bytes slice only once on creation and doesn't expect to allocate
1414// any more new memory for any of its operations thereafter. To apply any
1515// of its operations, some bits manipulations are required which implies
1616// some computational overhead. Thus providing a tradeoff between CPU time and memeory.
1717// Overhead grows lineraly proportionally to bit len and comparable with overhead
1818// provided by big.Int type operations. Unlike big.Int however, VarInt uses exact number
19- // of bits to store the numbers inside. Which makes VarInt extremely memory efficient. For example,
20- // to store a slice of 100 number 100 bit each, big.Int requires 12400 bits while
19+ // of bits to store the integers inside. Which makes VarInt extremely memory efficient. For example,
20+ // to store a slice of 100 integers 100 bit each, big.Int requires 12400 bits while
2121// VarInt needs exactly 10000 bits (excluding fixed internal overhead).
22- // In the same way VarInt also provides the efficient way to store numbers smaller than 64 bits.
23- // For example, to store a slice of 1000 number 2 bit each, []uin8 requires 8000 bits
22+ // In the same way VarInt also provides the efficient way to store integers smaller than 64 bits.
23+ // For example, to store a slice of 1000 integers 2 bit each, []uin8 requires 8000 bits
2424// while VarInt needs exactly 2000 bits (excluding fixed internal overhead).
2525// Note however, that VarInt is no way close to be optimized as well as big.Int, and
26- // provides a diminishing returns as bit length grows above certain threshold. Currently,
26+ // provides diminishing returns as bit length grows above certain threshold. Currently,
2727// in a conscious decision multiple operations implemented in favor of simplicity and
2828// not computational complexity, this includes Mul that uses standard long multiplication
2929// instead of fast multiplication algorithms like Karatsuba multiplication, and Div that
3030// uses standard slow division instead of fast division algorithms. The main rationale behind
31- // the choice is the fact that VarInt has the most efficiency when used for small and medium size numbers
31+ // the choice is the fact that VarInt has the most efficiency when used for small and medium size integers
3232// in the range of 1 to 5000 bits, therefore asymptotic complexity should have less of impact.
3333// VarInt carries a small fixed overhead internaly, it allocates 2 separate uint cells at the beginning
3434// of the numeric bytes slice to store length and bit length somewhere. It also collocates extra Bits
@@ -41,7 +41,7 @@ const wsize = math_bits.UintSize
4141type VarInt []uint
4242
4343// NewVarInt allocates and returns VarInt instance that is capable to
44- // fit the provided len number of items each of the provided bit len in size .
44+ // fit the provided number of integers each of the provided bit len in width .
4545// In case the provided bit len is not positive, invalid number and ErrorBitLengthIsNotPositive is returned.
4646// In case the len is not positive, invalid number and ErrorLengthIsNotPositive is returned.
4747// In case the provided bit len is larger than predefined threshold of 4096,
@@ -56,7 +56,7 @@ func NewVarInt(blen, len int) (VarInt, error) {
5656 if len <= 0 {
5757 return nil , ErrorLengthIsNotPositive
5858 }
59- // Calculate capacity to fit all numbers with
59+ // Calculate capacity to fit all integers with
6060 // provided bit length and capacity.
6161 cap := (blen * len + wsize - 1 )/ wsize + 2
6262 // Calculate number of whole words plus
@@ -85,7 +85,7 @@ func NewVarInt(blen, len int) (VarInt, error) {
8585 }
8686}
8787
88- // Get sets the provided bits to the number inside VarInt at the provided index.
88+ // Get sets the provided bits to the integer inside VarInt at the provided index.
8989// It never allocates new Bits, the provided Bits are expected to be preallocated by the caller.
9090// In case the operation is used on invalid nil VarInt, ErrorVarIntIsInvalid is returned.
9191// In case negative index is provided, ErrorIndexIsNegative is returned.
@@ -143,7 +143,7 @@ func (vint VarInt) Get(i int, bits Bits) error {
143143 return nil
144144}
145145
146- // Set sets the provided bits into the number inside VarInt at the provided index.
146+ // Set sets the provided bits into the integer inside VarInt at the provided index.
147147// In case the operation is used on invalid nil VarInt, ErrorVarIntIsInvalid is returned.
148148// In case negative index is provided, ErrorIndexIsNegative is returned.
149149// In case the provided index is greater than len of VarInt, ErrorIndexIsOutOfRange is returned.
@@ -207,7 +207,7 @@ func (vint VarInt) Set(i int, bits Bits) error {
207207 return nil
208208}
209209
210- // GetSet swaps the provided bits with the number inside VarInt at the provided index.
210+ // GetSet swaps the provided bits with the integer inside VarInt at the provided index.
211211// In case the operation is used on invalid nil VarInt, ErrorVarIntIsInvalid is returned.
212212// In case negative index is provided, ErrorIndexIsNegative is returned.
213213// In case the provided index is greater than len of VarInt, ErrorIndexIsOutOfRange is returned.
@@ -277,7 +277,7 @@ func (vint VarInt) GetSet(i int, bits Bits) error {
277277 return nil
278278}
279279
280- // Add adds the provided bits to the number inside VarInt at the provided index.
280+ // Add adds the provided bits to the integer inside VarInt at the provided index.
281281// In case the operation is used on invalid nil VarInt, ErrorVarIntIsInvalid is returned.
282282// In case negative index is provided, ErrorIndexIsNegative is returned.
283283// In case the provided index is greater than len of VarInt, ErrorIndexIsOutOfRange is returned.
@@ -373,12 +373,12 @@ func (vint VarInt) Add(i int, bits Bits) error {
373373 return nil
374374}
375375
376- // Sub subtracts the provided bits from the number inside VarInt at the provided index.
376+ // Sub subtracts the provided bits from the integer inside VarInt at the provided index.
377377// In case the operation is used on invalid nil VarInt, ErrorVarIntIsInvalid is returned.
378378// In case negative index is provided, ErrorIndexIsNegative is returned.
379379// In case the provided index is greater than len of VarInt, ErrorIndexIsOutOfRange is returned.
380380// In case the provided bits has different bit len, ErrorUnequalBitLengthCardinality is returned.
381- // In case the subtraction result underflows the number , the regular unsigned semantic applies and
381+ // In case the subtraction result underflows the integer , the regular unsigned semantic applies and
382382// extra ErrorSubtractionUnderflow warning is returned.
383383func (vint VarInt ) Sub (i int , bits Bits ) error {
384384 // Check explicitly for invalid number.
@@ -460,12 +460,12 @@ func (vint VarInt) Sub(i int, bits Bits) error {
460460 return nil
461461}
462462
463- // Mul multiplies the provided bits with the number inside VarInt at the provided index.
463+ // Mul multiplies the provided bits with the integer inside VarInt at the provided index.
464464// In case the operation is used on invalid nil VarInt, ErrorVarIntIsInvalid is returned.
465465// In case negative index is provided, ErrorIndexIsNegative is returned.
466466// In case the provided index is greater than len of VarInt, ErrorIndexIsOutOfRange is returned.
467467// In case the provided bits has different bit len, ErrorUnequalBitLengthCardinality is returned.
468- // In case the multiplication result overflows the bit len, the number is trucated and
468+ // In case the multiplication result overflows the bit len, the integer is trucated and
469469// extra ErrorMultiplicationOverflow warning is returned.
470470func (vint VarInt ) Mul (i int , bits Bits ) error {
471471 // Check explicitly for invalid number.
@@ -550,15 +550,15 @@ func (vint VarInt) Mul(i int, bits Bits) error {
550550 }
551551 }
552552 // After multiplication is done set bits var
553- // back to i-th number and check for any error.
553+ // back to i-th integer and check for any error.
554554 _ = vint .Set (i , bvar )
555555 if overflow {
556556 return ErrorMultiplicationOverflow
557557 }
558558 return nil
559559}
560560
561- // Div divides the provided bits with the number inside VarInt at the provided index.
561+ // Div divides the provided bits with the integer inside VarInt at the provided index.
562562// In case the operation is used on invalid nil VarInt, ErrorVarIntIsInvalid is returned.
563563// In case negative index is provided, ErrorIndexIsNegative is returned.
564564// In case the provided index is greater than len of VarInt, ErrorIndexIsOutOfRange is returned.
@@ -622,7 +622,7 @@ func (vint VarInt) Div(i int, bits Bits) error {
622622 return nil
623623}
624624
625- // Mod applies modulo operation to the provided bits and the number inside VarInt at the provided index.
625+ // Mod applies modulo operation to the provided bits and the integer inside VarInt at the provided index.
626626// In case the operation is used on invalid nil VarInt, ErrorVarIntIsInvalid is returned.
627627// In case negative index is provided, ErrorIndexIsNegative is returned.
628628// In case the provided index is greater than len of VarInt, ErrorIndexIsOutOfRange is returned.
@@ -637,12 +637,12 @@ func (vint VarInt) Mod(i int, bits Bits) error {
637637 return err
638638 }
639639 // Get tmp bits variable with reminder inise,
640- // don't clear the previous and swap it with vint number .
640+ // don't clear the previous and swap it with vint.
641641 _ = vint .GetSet (i , bvar (vint , false ))
642642 return nil
643643}
644644
645- // Not applies bitwise negation ^ operation to the number inside VarInt at the provided index.
645+ // Not applies bitwise negation ^ operation to the integer inside VarInt at the provided index.
646646// In case the operation is used on invalid nil VarInt, ErrorVarIntIsInvalid is returned.
647647// In case negative index is provided, ErrorIndexIsNegative is returned.
648648// In case the provided index is greater than len of VarInt, ErrorIndexIsOutOfRange is returned.
@@ -700,7 +700,7 @@ func (vint VarInt) Not(i int) error {
700700 return nil
701701}
702702
703- // And applies bitwise and & operation to the provided bits and the number inside VarInt at the provided index.
703+ // And applies bitwise and & operation to the provided bits and the integer inside VarInt at the provided index.
704704// In case the operation is used on invalid nil VarInt, ErrorVarIntIsInvalid is returned.
705705// In case negative index is provided, ErrorIndexIsNegative is returned.
706706// In case the provided index is greater than len of VarInt, ErrorIndexIsOutOfRange is returned.
@@ -764,7 +764,7 @@ func (vint VarInt) And(i int, bits Bits) error {
764764 return nil
765765}
766766
767- // Or applies bitwise and | operation to the provided bits and the number inside VarInt at the provided index.
767+ // Or applies bitwise and | operation to the provided bits and the integer inside VarInt at the provided index.
768768// In case the operation is used on invalid nil VarInt, ErrorVarIntIsInvalid is returned.
769769// In case negative index is provided, ErrorIndexIsNegative is returned.
770770// In case the provided index is greater than len of VarInt, ErrorIndexIsOutOfRange is returned.
@@ -828,7 +828,7 @@ func (vint VarInt) Or(i int, bits Bits) error {
828828 return nil
829829}
830830
831- // Xor applies bitwise and ^ operation to the provided bits and the number inside VarInt at the provided index.
831+ // Xor applies bitwise and ^ operation to the provided bits and the integer inside VarInt at the provided index.
832832// In case the operation is used on invalid nil VarInt, ErrorVarIntIsInvalid is returned.
833833// In case negative index is provided, ErrorIndexIsNegative is returned.
834834// In case the provided index is greater than len of VarInt, ErrorIndexIsOutOfRange is returned.
@@ -892,7 +892,7 @@ func (vint VarInt) Xor(i int, bits Bits) error {
892892 return nil
893893}
894894
895- // Rsh applies right shift >> operation to the number inside VarInt at the provided index.
895+ // Rsh applies right shift >> operation to the integer inside VarInt at the provided index.
896896// In case the operation is used on invalid nil VarInt, ErrorVarIntIsInvalid is returned.
897897// In case negative shift is provided, ErrorShiftIsNegative is returned.
898898// In case negative index is provided, ErrorIndexIsNegative is returned.
@@ -976,7 +976,7 @@ loop:
976976 return nil
977977}
978978
979- // Lsh applies left shift << operation to the number inside VarInt at the provided index.
979+ // Lsh applies left shift << operation to the integer inside VarInt at the provided index.
980980// In case the operation is used on invalid nil VarInt, ErrorVarIntIsInvalid is returned.
981981// In case negative shift is provided, ErrorShiftIsNegative is returned.
982982// In case negative index is provided, ErrorIndexIsNegative is returned.
0 commit comments