Convert-UUlib
view release on metacpan or search on metacpan
uulib/crc32.c view on Meta::CPAN
* and prepend length(A) zeros to B and call it B' (think of it as 0000BBB)
* then exists a C' = A' ^ B'
* - remember: if you XOR someting with zero, it remains unchanged: X ^ 0 = X
* - that means C' = A concat B so that crc(A concat B) = crc(C') = crc(A') ^ crc(B')
* - the trick is to compute crc(A') based on crc(A)
* and crc(B') based on crc(B)
* - since B' starts with many zeros, the crc of those initial zeros is still zero
* - that means crc(B') = crc(B)
* - unfortunately the trailing zeros of A' change the crc, so usually crc(A') != crc(A)
* - the following code is a fast algorithm to compute crc(A')
* - starting with crc(A) and appending length(B) zeros, needing just log2(length(B)) iterations
* - the details are explained by the original author at
* https://stackoverflow.com/questions/23122312/crc-calculation-of-a-mostly-static-data-stream/23126768
*
* notes:
* - I squeezed everything into one function to keep global namespace clean (original code two helper functions)
* - most original comments are still in place, I added comments where these helper functions where made inline code
* - performance-wise there isn't any differenze to the original zlib/pigz code
*/
/* degenerated case */
( run in 0.487 second using v1.01-cache-2.11-cpan-71847e10f99 )