Open medo64 opened 1 year ago
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.
The polynomial values should be integers, not spans.
The polynomial values should be integers, not spans.
I tend to agree with you but I proposed it to be spans for the following two reasons:
I believe the proper type would be uint and unsigned integers used to be frowned upon in the public API
Most of functions that output hash (e.g. GetCurrentHash or GetHashAndReset) actually use spans for hash value. One function that doesn't follow that rule is GetCurrentHash that returns bytes. Since existing class/interface already uses spans for hash outputs, it seemed appropriate to accept polynomial in the same venue.
unsigned integers used to be frowned upon in the public API
Used to be. Not anymore. You might think of CLS compliance, which is a concept no longer relevant.
The disadvantage of accepting spans is that it falsely communicates to the user that they can pass a span of any length, while only spans of four or eight bytes are allowed.
Background and motivation
There are many variants of CRC32 algorithm that differ only in polynomials used. The current implementation only supports IEEE 802.3 polynomial externally. It would be ideal if class would allow for defining custom polynomial thus supporting other CRC-32 variants (e.g. ISCSI, MPEG-2, etc.)
Looking at source, there is a
Generate
method in Crc32ReflectedTable so basic plumbing for custom polynomials seems to be there already.As different polynomials use different initial and output XOR values, that would need to be added.
API Proposal
API Usage
Alternative Designs
No response
Risks
No response