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

Add support for 32-, 64-, 128-, 256-, 512-, 1024- bit flavours #4

Closed
wants to merge 3 commits into from

Conversation

lunaticmonk
Copy link

@lunaticmonk lunaticmonk commented Jan 25, 2019

Fixes #3

@sindresorhus
Copy link
Owner

Read the issue again. It's mentions BigInt. This will also require some tests and docs changes.

@lunaticmonk
Copy link
Author

@sindresorhus I did some changes. Please review. However, xo is throwing linting errors like BigInt is not defined., A function with a name starting with an uppercase letter should only be used as a constructor.. Is there a way I can ignore them by modifying some configs?

@sindresorhus
Copy link
Owner

I think the 64-, 128-, 256-, 512-, 1024 versions should be a separate method: fnv1a.bigInt() which should accept an options-object, so fnv1a.bigInt({bits: 128}). The method should validate that only the allowed bit versions are supplied.

@lunaticmonk
Copy link
Author

@sindresorhus Okay, will do that. Also, don't you think 64 bit can be solved normally rather than pushing it to bigInt?

@sindresorhus
Copy link
Owner

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) {
Copy link
Owner

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'));
Copy link
Owner

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,
Copy link
Owner

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.

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

Successfully merging this pull request may close these issues.

Support higher bit variants
2 participants