-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hash: add Combine functions #12297
Comments
You can already do CRC of multiple large byte slices without copying.
Your proposal would still be useful for computing the checksums in parallel (or at different times). I'm not sure how often that comes up. |
The advantage is not gained from avoiding copying, but rather from avoiding the need to compute the full hash. If The algorithm used by zlib can combine Useful applications of this:
|
I would be very amused to see this happen. I did this work for Java (in particular, fork/join CRC calculation) and it was judged to be too scary for incorporation into the Java standard library because it used threads. For CRCs that use different polynomials than the one wired into the CRC32 instruction, you can (on sufficiently modern AMD64) use carryless multiply to get a nice serial speed boost, too. |
(Searched my name by accient ;) Wouldn't this be a nice feature of a third party package? I don't see much use for it in general, so IMO it doesn't belong in the standard package. Even in pgzip, it wouldn't really help, since crc is done in the calling goroutine, which doesn't have the "heavy" load. |
@klauspost I agree. I still need/desire this feature, but I'm sure most people probably won't need this. As such, it fits better in a third-party package. Closing my issue down, unless many other people voice a need for this. |
I propose that the standard libraries hash/crc32, hash/crc64, and hash/adler32 add a Combine function that does the following:
Let AB be the string concatenation of strings A and B. Then it is possible to define a efficient function Combine that computes Hash(AB) given only Hash(A), Hash(B), Len(B).
Thus, usage of Combine in hash/crc32 may look like:
The zlib library provides these functions and they are extremely useful for merging large data segments under a single hash or for computing the hash of a large dataset in parallel.
Advantages
Disadvantages
I'd be interested in adding these if other people find them useful as well.
The text was updated successfully, but these errors were encountered: