@esfaenza/extensions 11.2.11 → 11.2.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1303,33 +1303,27 @@
1303
1303
  if (navigateFullDepth === void 0) { navigateFullDepth = false; }
1304
1304
  if (precise === void 0) { precise = false; }
1305
1305
  var strDef = this.stringify(o, level, navigateFullDepth);
1306
- var hash = precise ? this.md5(strDef) : this.superSimpleHash(strDef);
1306
+ var hash = precise ? this.md5(strDef) : this.simpleHash(strDef);
1307
1307
  return hash;
1308
1308
  };
1309
1309
  /**
1310
- * Hash più semplice e più veloce dell'md5, ma meno sicuro... vediamo come va
1310
+ * Hash più semplice e più veloce dell'md5, ma meno sicuro
1311
1311
  *
1312
- * @param {string} str Stringa di cui calcolare l'hash
1313
- */
1314
- HashingService.prototype.simpleHash = function (str) {
1315
- var hash = 0;
1316
- for (var i = 0; i < str.length; i++) {
1317
- var char = str.charCodeAt(i);
1318
- hash = (hash << 5) - hash + char;
1319
- hash &= hash; // Convert to 32bit integer
1320
- }
1321
- return new Uint32Array([hash])[0].toString(36);
1322
- };
1323
- /**
1324
- * Hash più semplice e più veloce dell'md5, ma meno sicuro... vediamo come va
1312
+ * Vedi https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript
1325
1313
  *
1326
1314
  * @param {string} str Stringa di cui calcolare l'hash
1327
1315
  */
1328
- HashingService.prototype.superSimpleHash = function (str) {
1329
- var h, i;
1330
- for (i = 0, h = 0; i < str.length; i++)
1331
- h = Math.imul(31, h) + str.charCodeAt(i) | 0;
1332
- return h.toString();
1316
+ HashingService.prototype.simpleHash = function (str, seed) {
1317
+ if (seed === void 0) { seed = 0; }
1318
+ var h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed;
1319
+ for (var i = 0, ch = void 0; i < str.length; i++) {
1320
+ ch = str.charCodeAt(i);
1321
+ h1 = Math.imul(h1 ^ ch, 2654435761);
1322
+ h2 = Math.imul(h2 ^ ch, 1597334677);
1323
+ }
1324
+ h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
1325
+ h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
1326
+ return (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString();
1333
1327
  };
1334
1328
  /**
1335
1329
  * Genera una stringa che identifica univocamente l'oggetto in questione