hash.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. /**
  7. * JS Implementation of MurmurHash2
  8. *
  9. * @author <a href="mailto:gary.court@gmail.com">Gary Court</a>
  10. * @see http://github.com/garycourt/murmurhash-js
  11. * @author <a href="mailto:aappleby@gmail.com">Austin Appleby</a>
  12. * @see http://sites.google.com/site/murmurhash/
  13. *
  14. * @param {string} str ASCII only
  15. * @return {string} Base 36 encoded hash result
  16. */
  17. function murmurhash2_32_gc(str) {
  18. var l = str.length;
  19. var h = l;
  20. var i = 0;
  21. var k;
  22. while (l >= 4) {
  23. k = str.charCodeAt(i) & 0xff | (str.charCodeAt(++i) & 0xff) << 8 | (str.charCodeAt(++i) & 0xff) << 16 | (str.charCodeAt(++i) & 0xff) << 24;
  24. k = (k & 0xffff) * 0x5bd1e995 + (((k >>> 16) * 0x5bd1e995 & 0xffff) << 16);
  25. k ^= k >>> 24;
  26. k = (k & 0xffff) * 0x5bd1e995 + (((k >>> 16) * 0x5bd1e995 & 0xffff) << 16);
  27. h = (h & 0xffff) * 0x5bd1e995 + (((h >>> 16) * 0x5bd1e995 & 0xffff) << 16) ^ k;
  28. l -= 4;
  29. ++i;
  30. } // forgive existing code
  31. /* eslint-disable no-fallthrough */
  32. switch (l) {
  33. case 3:
  34. h ^= (str.charCodeAt(i + 2) & 0xff) << 16;
  35. case 2:
  36. h ^= (str.charCodeAt(i + 1) & 0xff) << 8;
  37. case 1:
  38. h ^= str.charCodeAt(i) & 0xff;
  39. h = (h & 0xffff) * 0x5bd1e995 + (((h >>> 16) * 0x5bd1e995 & 0xffff) << 16);
  40. }
  41. /* eslint-enable no-fallthrough */
  42. h ^= h >>> 13;
  43. h = (h & 0xffff) * 0x5bd1e995 + (((h >>> 16) * 0x5bd1e995 & 0xffff) << 16);
  44. h ^= h >>> 15;
  45. return (h >>> 0).toString(36);
  46. }
  47. var _default = murmurhash2_32_gc;
  48. exports.default = _default;