phash2 portability

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

phash2 portability

Schneider-3
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?

Thanks


Frans

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: phash2 portability

Lukas Larsson-8


On Wed, Aug 28, 2019 at 8:45 AM Frans Schneider <[hidden email]> 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
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: phash2 portability

Richard O'Keefe
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 <[hidden email]> wrote:


On Wed, Aug 28, 2019 at 8:45 AM Frans Schneider <[hidden email]> 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
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: phash2 portability

Lukas Larsson-8


On Mon, Sep 2, 2019 at 12:37 PM Richard O'Keefe <[hidden email]> 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 <[hidden email]> wrote:


On Wed, Aug 28, 2019 at 8:45 AM Frans Schneider <[hidden email]> 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
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions