Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unnecessary plus one for :erlang.phash() #12

Closed
nhooyr opened this issue May 30, 2017 · 3 comments
Closed

unnecessary plus one for :erlang.phash() #12

nhooyr opened this issue May 30, 2017 · 3 comments

Comments

@nhooyr
Copy link

nhooyr commented May 30, 2017

:erlang.phash() already puts the number between 1..n, no need to add one.

@sasa1977
Copy link
Owner

The function used in the code is :erlang.phash2 (notice the trailing 2 in the name), which returns the result in the range of 0..(n-1) (see here), so +1 is needed in this case.

Thanks for submitting the issue anyway :-)

@nhooyr
Copy link
Author

nhooyr commented May 31, 2017

Oh, why not use :erlang.phash then?

@sasa1977
Copy link
Owner

sasa1977 commented May 31, 2017

The docs for phash2 state the following:

This BIF is always to be used for hashing terms. It distributes small integers better than phash/2, and it is faster for bignums and binaries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants