-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
Add support for 32-, 64-, 128-, 256-, 512-, 1024- bit flavours #4
Conversation
Read the issue again. It's mentions |
3ef3d30
to
206c105
Compare
@sindresorhus I did some changes. Please review. However, |
I think the 64-, 128-, 256-, 512-, 1024 versions should be a separate method: |
@sindresorhus Okay, will do that. Also, don't you think 64 bit can be solved normally rather than pushing it to bigInt? |
No, and if you think that, I'm questioning whether you're up to the task to resolve this correctly. |
index.js
Outdated
}; | ||
|
||
function getBigInt(int) { | ||
if (typeof (int) === Number) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check is not correct.
index.js
Outdated
*/ | ||
for (let i = 0; i < string.length; i++) { | ||
hash ^= getBigInt(string.charCodeAt(i).toString()); | ||
hash += (hash << getBigInt('1')) + (hash << getBigInt('4')) + (hash << getBigInt('7')) + (hash << getBigInt('8')) + (hash << getBigInt('24')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure the algorithm is exactly the same for larger numbers? Please read up on the source material: http://www.isthe.com/chongo/tech/comp/fnv/index.html#FNV-param
index.js
Outdated
hash ^= string.charCodeAt(i); | ||
const OFFSET_BASIS = { | ||
32: 2166136261, | ||
64: 14695981039346656037, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JavaScript does not support 64-bit numbers.
Fixes #3