[erlang-questions] phash2 portability

Richard O'Keefe raoknz@REDACTED
Mon Sep 2 12:36:51 CEST 2019


Hashing maps using xor?  Oh dear.  That's really not a good method.
I found a much better way to hash sets and maps, but couldn't find
a journal that thought it was in their scope.  Actually, there are
several good ways.

Now you are locked into an inferior one.

On Thu, 29 Aug 2019 at 03:19, Lukas Larsson <lukas@REDACTED> wrote:

>
>
> On Wed, Aug 28, 2019 at 8:45 AM Frans Schneider <fchschneider@REDACTED>
> wrote:
>
>> Hi list,
>>
>> According to the docs, the erlang:phash2/2 will return the same result
>> regardless of machine architecture and ERTS version. Does this imply
>> that this is still true in case the implementation of a basic type, lets
>> say a list or map (#{}), will change in the future? Can I assume that
>> calculating a hash for a list will have the same result now and in the
>> future?
>>
>
> Yes. The way hashing of maps works is that it hashes each k/v pair and
> then takes the xor of each of those hashes. Since a series of xor's can be
> applied in any order without changing the result, the hash value will
> always be the same.
>
>
>>
>> Thanks
>>
>>
>> Frans
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20190902/8af64587/attachment.htm>


More information about the erlang-questions mailing list