UNPKG

767 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.DeterministicUuidRegistry = void 0;
4class DeterministicUuidRegistry {
5 static get(str, inc = 0) {
6 const id = inc ? this.hashCode(`${str}_${inc}`) : this.hashCode(str);
7 if (this.registry.has(id)) {
8 return this.get(str, inc + 1);
9 }
10 this.registry.set(id, true);
11 return id;
12 }
13 static clear() {
14 this.registry.clear();
15 }
16 static hashCode(s) {
17 let h = 0;
18 for (let i = 0; i < s.length; i++)
19 h = (Math.imul(31, h) + s.charCodeAt(i)) | 0;
20 return h.toString();
21 }
22}
23exports.DeterministicUuidRegistry = DeterministicUuidRegistry;
24DeterministicUuidRegistry.registry = new Map();