UNPKG

@dynatrace/opentelemetry-core

Version:

Dynatrace OpenTelemetry core package

67 lines (64 loc) 2.65 kB
"use strict"; /* Copyright 2022 Dynatrace LLC Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.murmurhash64a = murmurhash64a; const Long = require("long"); // ============================================================================ const m = new Long(0x5bd1e995, 0xc6a4a793, true); const r = 47; // ---------------------------------------------------------------------------- function murmurhash64a(s, seed = new Long(0xe17a1465, 0, true)) { if (typeof (seed) === "number") { seed = Long.fromNumber(seed, true); } const data = Buffer.from(s); const len = data.length; let h = seed.xor(m.mul(len)); const reminder = len % 8; const cnt = len - reminder; let pos; for (pos = 0; pos < cnt; pos += 8) { let k = new Long(data.readInt32LE(pos), data.readInt32LE(pos + 4), true); k = k.mul(m); k = k.xor(k.shiftRightUnsigned(r)); k = k.mul(m); h = h.xor(k); h = h.mul(m); } switch (reminder) { /* eslint-disable no-bitwise */ //@ts-ignore Fallthrough case in switch. case 7: h = h.xor(new Long(0, data[pos + 6] << 16, true)); //@ts-ignore Fallthrough case in switch. case 6: h = h.xor(new Long(0, data[pos + 5] << 8, true)); //@ts-ignore Fallthrough case in switch. case 5: h = h.xor(new Long(0, data[pos + 4], true)); //@ts-ignore Fallthrough case in switch. case 4: h = h.xor(new Long(data[pos + 3] << 24, 0, true)); //@ts-ignore Fallthrough case in switch. case 3: h = h.xor(new Long(data[pos + 2] << 16, 0, true)); //@ts-ignore Fallthrough case in switch. case 2: h = h.xor(new Long(data[pos + 1] << 8, 0, true)); //@ts-ignore Fallthrough case in switch. case 1: h = h.xor(new Long(data[pos], 0, true)); h = h.mul(m); /* eslint-enable no-bitwise */ } h = h.xor(h.shiftRightUnsigned(r)); h = h.mul(m); h = h.xor(h.shiftRightUnsigned(r)); return h; } //# sourceMappingURL=MurmurHash.js.map