Switched to CRC as seed collection function instead of xor
As noted by gtaska, we are sitting on a better hash-combining function than xor: CRC. Previous issues with xor were solvable, but relying on xor for this isn't really worth the risk when we already have a CRC function readily available. To quote a study found by gtaska: https://michiel.buddingh.eu/distribution-of-hash-values > CRC32 seems to score really well, but its graph is skewed by the results > of Dataset 5 (binary numbers), which may or may not be too synthetic to > be considered a fair benchmark. But even if you substract the results > from that test, it does not fare significantly worse than other, > cryptographic hash functions.
This commit is contained in:
@@ -872,8 +872,10 @@ static lfs_stag_t lfs_dir_fetchmatch(lfs_t *lfs,
|
|||||||
ptag ^= (lfs_tag_t)(lfs_tag_chunk(tag) & 1U) << 31;
|
ptag ^= (lfs_tag_t)(lfs_tag_chunk(tag) & 1U) << 31;
|
||||||
|
|
||||||
// toss our crc into the filesystem seed for
|
// toss our crc into the filesystem seed for
|
||||||
// pseudorandom numbers
|
// pseudorandom numbers, note we use another crc here
|
||||||
lfs->seed ^= crc;
|
// as a collection function because it is sufficiently
|
||||||
|
// random and convenient
|
||||||
|
lfs->seed = lfs_crc(lfs->seed, &crc, sizeof(crc));
|
||||||
|
|
||||||
// update with what's found so far
|
// update with what's found so far
|
||||||
besttag = tempbesttag;
|
besttag = tempbesttag;
|
||||||
|
|||||||
Reference in New Issue
Block a user