Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,6 @@
"fast-glob": "^3.3.2",
"fastest-levenshtein": "^1.0.16",
"file-saver": "^2.0.5",
"fnv-plus": "^1.3.1",
"formik": "^2.4.6",
"fp-ts": "^2.3.1",
"fuse.js": "^7.0.0",
Expand Down Expand Up @@ -1719,7 +1718,6 @@
"@types/fetch-mock": "^7.3.1",
"@types/file-saver": "^2.0.7",
"@types/flot": "^0.0.31",
"@types/fnv-plus": "^1.3.2",
"@types/geojson": "^7946.0.10",
"@types/getos": "^3.0.4",
"@types/gulp": "^4.0.17",
Expand Down
19 changes: 0 additions & 19 deletions renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -3976,25 +3976,6 @@
"minimumReleaseAge": "7 days",
"enabled": true
},
{
"groupName": "fnv-plus",
"matchDepNames": [
"fnv-plus",
"@types/fnv-plus"
],
"reviewers": [
"team:obs-ux-infra_services-team"
],
"matchBaseBranches": [
"main"
],
"labels": [
"release_note:skip",
"backport:all-open"
],
"minimumReleaseAge": "7 days",
"enabled": true
},
{
"groupName": "hdr-histogram-js",
"matchDepNames": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { fnv1a32 } from './hash';

describe('fnv-plus', function () {
const hash1 = 'hello world';
const hash2 = 'the quick brown fox jumps over the lazy dog';

describe('(32)', function () {
it('should generate a 32-bit hash if specified', function () {
const h1 = fnv1a32(hash1);
const h2 = fnv1a32(hash2);

expect(h1).toEqual(3582672807);
expect(h2).toEqual(4016652272);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { fast1a32 } from 'fnv-plus';
import { Fields } from '../entity';

export function hashKeysOf<T extends Fields>(source: T, keys: Array<keyof T>) {
Expand All @@ -19,6 +18,73 @@ export function hashKeysOf<T extends Fields>(source: T, keys: Array<keyof T>) {
return hashed;
}

// this hashing function is the same as fnv-plus
export function fnv1a32(str: string): number {
/* eslint-disable no-bitwise */
let i;
const l = str.length - 3;
let t0 = 0;
let v0 = 0x9dc5;
let t1 = 0;
let v1 = 0x811c;

for (i = 0; i < l; ) {
v0 ^= str.charCodeAt(i++);
t0 = v0 * 403;
t1 = v1 * 403;

t1 += v0 << 8;

v1 = (t1 + (t0 >>> 16)) & 65535;

v0 = t0 & 65535;

v0 ^= str.charCodeAt(i++);
t0 = v0 * 403;
t1 = v1 * 403;

t1 += v0 << 8;

v1 = (t1 + (t0 >>> 16)) & 65535;

v0 = t0 & 65535;

v0 ^= str.charCodeAt(i++);
t0 = v0 * 403;
t1 = v1 * 403;

t1 += v0 << 8;

v1 = (t1 + (t0 >>> 16)) & 65535;

v0 = t0 & 65535;

v0 ^= str.charCodeAt(i++);
t0 = v0 * 403;
t1 = v1 * 403;

t1 += v0 << 8;

v1 = (t1 + (t0 >>> 16)) & 65535;

v0 = t0 & 65535;
}

while (i < l + 3) {
v0 ^= str.charCodeAt(i++);
t0 = v0 * 403;
t1 = v1 * 403;

t1 += v0 << 8;

v1 = (t1 + (t0 >>> 16)) & 65535;

v0 = t0 & 65535;
}

return ((v1 << 16) >>> 0) + v0;
}

export function appendHash(hash: string, value: string) {
return fast1a32(hash + ',' + value).toString();
return fnv1a32(hash + ',' + value).toString();
}
10 changes: 0 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12700,11 +12700,6 @@
dependencies:
"@types/jquery" "*"

"@types/fnv-plus@^1.3.2":
version "1.3.2"
resolved "https://registry.yarnpkg.com/@types/fnv-plus/-/fnv-plus-1.3.2.tgz#bd591c1031ae48a18c99eaa60f659288aea545c0"
integrity sha512-Bgr5yn2dph2q8HZKDS002Pob6vaRTRfhqN9E+TOhjKsJvnfZXULPR3ihH8dL5ZjgxbNhqhTn9hijpbAMPtKZzw==

"@types/gensync@^1.0.0":
version "1.0.4"
resolved "https://registry.yarnpkg.com/@types/gensync/-/gensync-1.0.4.tgz#7122d8f0cd3bf437f9725cc95b180197190cf50b"
Expand Down Expand Up @@ -20393,11 +20388,6 @@ fn.name@1.x.x:
resolved "https://registry.yarnpkg.com/fn.name/-/fn.name-1.1.0.tgz#26cad8017967aea8731bc42961d04a3d5988accc"
integrity sha512-GRnmB5gPyJpAhTQdSZTSp9uaPSvl09KoYcMQtsB9rQoOmzs9dH6ffeccH+Z+cv6P68Hu5bC6JjRh4Ah/mHSNRw==

fnv-plus@^1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/fnv-plus/-/fnv-plus-1.3.1.tgz#c34cb4572565434acb08ba257e4044ce2b006d67"
integrity sha512-Gz1EvfOneuFfk4yG458dJ3TLJ7gV19q3OM/vVvvHf7eT02Hm1DleB4edsia6ahbKgAYxO9gvyQ1ioWZR+a00Yw==

focus-lock@^0.11.6:
version "0.11.6"
resolved "https://registry.yarnpkg.com/focus-lock/-/focus-lock-0.11.6.tgz#e8821e21d218f03e100f7dc27b733f9c4f61e683"
Expand Down