Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // CRC-3-GSM: x^3 + x^1 + 1 GSM3 = &Poly[uint8]{Word: 3, Width: 3} )
Functions ¶
func BitwiseUpdateFn ¶
BitwiseUpdateFn returns a function that returns the result of adding the bits defined by data and dataWidth into the crc. The actual function returned depends on the polynomial's representation (normal or reversed form).
func UpdateBitwise ¶
Types ¶
type Poly ¶
Poly defines a polynomial in a specific representation.
Example ¶
This example calculates representations of the CCITT-16 polynomial as shown in https://en.wikipedia.org/wiki/Mathematics_of_cyclic_redundancy_checks#Polynomial_representations
package main import ( "fmt" ) var ccitt16 = &Poly[uint16]{Word: 0x1021, Width: 16} // This example calculates representations of the CCITT-16 // polynomial as shown in // https://en.wikipedia.org/wiki/Mathematics_of_cyclic_redundancy_checks#Polynomial_representations func main() { reversed := ccitt16.ReversedForm() fmt.Printf("%#04x %#04x %#04x", reversed.Word, ccitt16.ReciprocalForm().Word, reversed.ReciprocalForm().Word) }
Output: 0x8408 0x0811 0x8810
func (*Poly[T]) MakeTable ¶
func (poly *Poly[T]) MakeTable(opts ...TableOption) []T
MakeTable creates a lookup table for the specified polynomial. The size of the table returned equals the length of the value range determined by the number of data bits.
func (*Poly[T]) NormalForm ¶
NormalForm returns the normal form of the polynomial.
func (*Poly[T]) ReciprocalForm ¶
ReciprocalForm returns the reciprocal form of the polynomial that can be obtained by mirroring its coefficients. It returns the unchanged polynomial if it is already in its reciprocal form.
func (*Poly[T]) ReversedForm ¶
ReversedForm returns the reversed, lsbit-first form of the polynomial. It returns the unchanged polynomial if it is already in its reversed form.
type TableOption ¶
type TableOption func(*tableConf)
func WithDataWidth ¶
func WithDataWidth(w int) TableOption
WithDataWidthByte sets the data width to 8 bits, which will result in a table of 256 entries for byte-wise processing.
func WithInitialValue ¶
func WithInitialValue(initial uint32) TableOption
WithInitialValue ensures that when a table is created the specified initial value will be applied to the calculation of each table entry. In cases where a table later is used manually, like when a CRC is calulated over some bits only, this saves one XOR operation.
func WithReversedBits ¶
func WithReversedBits() TableOption
WithReversedBits table option mirrors the bits of each table entry.