[erlang-questions] phash2 portability

Lukas Larsson lukas@REDACTED
Mon Sep 2 13:17:41 CEST 2019


On Mon, Sep 2, 2019 at 12:37 PM Richard O'Keefe <raoknz@REDACTED> wrote:

> 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.
>

If you have any links to better methods it would be great to have them if
we ever decide to make a phash3 :) or maybe we can improve our internal
hash used by ets and friends that don't need to work across versions.


>
> 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
>>
> _______________________________________________
> 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/c3cca765/attachment.htm>


More information about the erlang-questions mailing list