diff --git a/package.json b/package.json index 7cc20c37d53fb..136ea884836b8 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/renovate.json b/renovate.json index e85ba2041cfd3..c3e7967e5e99b 100644 --- a/renovate.json +++ b/renovate.json @@ -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": [ diff --git a/src/platform/packages/shared/kbn-apm-synthtrace-client/src/lib/utils/hash.test.ts b/src/platform/packages/shared/kbn-apm-synthtrace-client/src/lib/utils/hash.test.ts new file mode 100644 index 0000000000000..ea9394471e3e6 --- /dev/null +++ b/src/platform/packages/shared/kbn-apm-synthtrace-client/src/lib/utils/hash.test.ts @@ -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); + }); + }); +}); diff --git a/src/platform/packages/shared/kbn-apm-synthtrace-client/src/lib/utils/hash.ts b/src/platform/packages/shared/kbn-apm-synthtrace-client/src/lib/utils/hash.ts index bdb96e2ee1ac5..e957af4d47ee1 100644 --- a/src/platform/packages/shared/kbn-apm-synthtrace-client/src/lib/utils/hash.ts +++ b/src/platform/packages/shared/kbn-apm-synthtrace-client/src/lib/utils/hash.ts @@ -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(source: T, keys: Array) { @@ -19,6 +18,73 @@ export function hashKeysOf(source: T, keys: Array) { 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(); } diff --git a/yarn.lock b/yarn.lock index b7f018dc63d36..08878d6167aa9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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"