You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think the Hash and Hasher behavior is underspecified here. I would assume that Hash::hash_slice is supposed to have the same effect as just hashing each item in the slice separately, without the length, as the default implementation does. But what about Hasher::write -- is write(&[1, 2, 3, 4]) supposed to match write(&[1, 2]); write(&[3, 4]);?
If both Hash::hash_slice and Hasher::write may consider length, then Hash for VecDeque is incorrect.
If Hash::hash_slice should hash without length, but Hasher::write is allowed to use length, then the integer optimization is incorrect.
If both Hash::hash_slice and Hasher::write are supposed to be independent of length, hashing identically whether it's one big slice or any partitioned slices of the same data, then AHasher::write is incorrect.
The text was updated successfully, but these errors were encountered:
(via rust-lang/hashbrown#218 (comment))
It seems ahash gets different values for a rotated (non-contiguous)
VecDeque
:(Playground)
Hash for VecDeque
hashes the length and then each part intoHash::hash_slice
:rust/library/alloc/src/collections/vec_deque/mod.rs
Lines 2650 to 2657 in 0fe1dc6
Hash::hash_slice
for integers casts to&[u8]
and callsHasher::write
:rust/library/core/src/hash/mod.rs
Lines 555 to 563 in 0fe1dc6
And finally,
AHasher::write
feeds the length of that slice in first, so it is sensitive to how the deque is split up!https://github.com/tkaitchuck/aHash/blob/b175b79659da44a85a01d27cb1f9e697bcaff89a/src/fallback_hash.rs#L159-L163
https://github.com/tkaitchuck/aHash/blob/b175b79659da44a85a01d27cb1f9e697bcaff89a/src/aes_hash.rs#L147-L150
I think the
Hash
andHasher
behavior is underspecified here. I would assume thatHash::hash_slice
is supposed to have the same effect as just hashing each item in the slice separately, without the length, as the default implementation does. But what aboutHasher::write
-- iswrite(&[1, 2, 3, 4])
supposed to matchwrite(&[1, 2]); write(&[3, 4]);
?Hash::hash_slice
andHasher::write
may consider length, thenHash for VecDeque
is incorrect.Hash::hash_slice
should hash without length, butHasher::write
is allowed to use length, then the integer optimization is incorrect.Hash::hash_slice
andHasher::write
are supposed to be independent of length, hashing identically whether it's one big slice or any partitioned slices of the same data, thenAHasher::write
is incorrect.The text was updated successfully, but these errors were encountered: