Skip to content

Commit

Permalink
Merge pull request #16 from nalinbhardwaj/fnv_hash
Browse files Browse the repository at this point in the history
Drop fnv-plus, handwrite fnv-hash
  • Loading branch information
jbaylina committed Jan 14, 2022
2 parents 181131c + e3fc396 commit 4efa12b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
17 changes: 11 additions & 6 deletions build/main.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@

Object.defineProperty(exports, '__esModule', { value: true });

var fnv = require('fnv-plus');
var ffjavascript = require('ffjavascript');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var fnv__default = /*#__PURE__*/_interopDefaultLegacy(fnv);

/*
Copyright 2020 0KIMS association.
Expand Down Expand Up @@ -44,7 +39,17 @@ function flatArray(a) {
}

function fnvHash(str) {
return fnv__default['default'].hash(str, 64).hex();
const uint64_max = BigInt(2) ** BigInt(64);
let hash = BigInt("0xCBF29CE484222325");
for (var i = 0; i < str.length; i++) {
hash ^= BigInt(str[i].charCodeAt());
hash *= BigInt(0x100000001B3);
hash %= uint64_max;
}
let shash = hash.toString(16);
let n = 16 - shash.length;
shash = '0'.repeat(n).concat(shash);
return shash;
}

/* globals WebAssembly */
Expand Down
14 changes: 11 additions & 3 deletions js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ limitations under the License.
*/

import fnv from "fnv-plus";

export function flatArray(a) {
var res = [];
fillArray(res, a);
Expand All @@ -35,5 +33,15 @@ export function flatArray(a) {
}

export function fnvHash(str) {
return fnv.hash(str, 64).hex();
const uint64_max = BigInt(2) ** BigInt(64);
let hash = BigInt("0xCBF29CE484222325");
for (var i = 0; i < str.length; i++) {
hash ^= BigInt(str[i].charCodeAt());
hash *= BigInt(0x100000001B3);
hash %= uint64_max;
}
let shash = hash.toString(16);
let n = 16 - shash.length;
shash = '0'.repeat(n).concat(shash);
return shash;
}
13 changes: 1 addition & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
},
"homepage": "https://github.com/iden3/circom_runtime#readme",
"dependencies": {
"ffjavascript": "0.2.39",
"fnv-plus": "^1.3.1"
"ffjavascript": "0.2.39"
},
"devDependencies": {
"eslint": "^6.8.0",
Expand Down

0 comments on commit 4efa12b

Please sign in to comment.