phash2 isn't very resistant to collisions?
Roger Lipscombe
roger@REDACTED
Wed Dec 15 12:57:40 CET 2021
I'm sure this has come up previously, but all I could find talked about atoms.
I know it's not intended to be cryptographically strong, but
erlang:phash2 is woefully collidey with 2-tuples:
Test = fun(N) ->
L = [{X, Y} || X <- lists:seq(0, N - 1), Y <- lists:seq(0, N - 1)],
Expected = N * N,
Expected = length(L),
Expected = length(lists:usort([erlang:phash2(Term) || Term <- L]))
end.
1> Test(10).
100
2> Test(100).
** exception error: no match of right hand side value 9999
3> Test(99).
** exception error: no match of right hand side value 9800
4> Test(500).
** exception error: no match of right hand side value 249763
What alternatives are there to phash2, if I still care about performance?
More information about the erlang-questions
mailing list