Guidance on hash collisions between different key types #89
-
Hi, I'd like to use
I'd like to use ahash on the padded strings, as efficiently as possible. That suggests using:
I have two questions: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
As the layout affects hashing which of 1,2, or 3 is fed in will affect the resulting hash. This means that one cannot assume the same string with different amounts of padding or stored in one of these formats will hash differently. In general collisions would only occur between hashes of different layouts when the data from one matches the other. For example (u64, u64) would collide with (u32, u32) with the same numeric values, because when hashing u32s are just treated as u64s. But as you mention above (u64, u64) would very likely not collide with (u64, u64, u128) because those involve a different sequence of calls. In terms of a faster result hashing a single u128 is faster than (u64, u64) ignoring any conversion cost. |
Beta Was this translation helpful? Give feedback.
As the layout affects hashing which of 1,2, or 3 is fed in will affect the resulting hash. This means that one cannot assume the same string with different amounts of padding or stored in one of these formats will hash differently. In general collisions would only occur between hashes of different layouts when the data from one matches the other. For example (u64, u64) would collide with (u32, u32) with the same numeric values, because when hashing u32s are just treated as u64s. But as you mention above (u64, u64) would very likely not collide with (u64, u64, u128) because those involve a different sequence of calls.
In terms of a faster result hashing a single u128 is faster than (u64, u…