fork download
  1. importPackage(java.io);
  2. importPackage(java.lang);
  3.  
  4. // +----------------------------------------------------------------------+
  5. // | murmurHash3.js v2.1.2 (http://g...content-available-to-author-only...b.com/karanlyons/murmurHash.js) |
  6. // | A javascript implementation of MurmurHash3's x86 hashing algorithms. |
  7. // |----------------------------------------------------------------------|
  8. // | Copyright (c) 2012 Karan Lyons |
  9. // | Freely distributable under the MIT license. |
  10. // +----------------------------------------------------------------------+
  11.  
  12.  
  13. ;(function (root, undefined) {
  14. 'use strict';
  15.  
  16. // Create a local object that'll be exported or referenced globally.
  17. var library = {
  18. 'version': '2.1.2',
  19. 'x86': {},
  20. 'x64': {}
  21. };
  22.  
  23.  
  24.  
  25.  
  26. // PRIVATE FUNCTIONS
  27. // -----------------
  28.  
  29. function _x86Multiply(m, n) {
  30. //
  31. // Given two 32bit ints, returns the two multiplied together as a
  32. // 32bit int.
  33. //
  34.  
  35. return ((m & 0xffff) * n) + ((((m >>> 16) * n) & 0xffff) << 16);
  36. }
  37.  
  38.  
  39. function _x86Rotl(m, n) {
  40. //
  41. // Given a 32bit int and an int representing a number of bit positions,
  42. // returns the 32bit int rotated left by that number of positions.
  43. //
  44.  
  45. return (m << n) | (m >>> (32 - n));
  46. }
  47.  
  48.  
  49. function _x86Fmix(h) {
  50. //
  51. // Given a block, returns murmurHash3's final x86 mix of that block.
  52. //
  53.  
  54. h ^= h >>> 16;
  55. h = _x86Multiply(h, 0x85ebca6b);
  56. h ^= h >>> 13;
  57. h = _x86Multiply(h, 0xc2b2ae35);
  58. h ^= h >>> 16;
  59.  
  60. return h;
  61. }
  62.  
  63.  
  64. function _x64Add(m, n) {
  65. //
  66. // Given two 64bit ints (as an array of two 32bit ints) returns the two
  67. // added together as a 64bit int (as an array of two 32bit ints).
  68. //
  69.  
  70. m = [m[0] >>> 16, m[0] & 0xffff, m[1] >>> 16, m[1] & 0xffff];
  71. n = [n[0] >>> 16, n[0] & 0xffff, n[1] >>> 16, n[1] & 0xffff];
  72. var o = [0, 0, 0, 0];
  73.  
  74. o[3] += m[3] + n[3];
  75. o[2] += o[3] >>> 16;
  76. o[3] &= 0xffff;
  77.  
  78. o[2] += m[2] + n[2];
  79. o[1] += o[2] >>> 16;
  80. o[2] &= 0xffff;
  81.  
  82. o[1] += m[1] + n[1];
  83. o[0] += o[1] >>> 16;
  84. o[1] &= 0xffff;
  85.  
  86. o[0] += m[0] + n[0];
  87. o[0] &= 0xffff;
  88.  
  89. return [(o[0] << 16) | o[1], (o[2] << 16) | o[3]];
  90. }
  91.  
  92.  
  93. function _x64Multiply(m, n) {
  94. //
  95. // Given two 64bit ints (as an array of two 32bit ints) returns the two
  96. // multiplied together as a 64bit int (as an array of two 32bit ints).
  97. //
  98.  
  99. m = [m[0] >>> 16, m[0] & 0xffff, m[1] >>> 16, m[1] & 0xffff];
  100. n = [n[0] >>> 16, n[0] & 0xffff, n[1] >>> 16, n[1] & 0xffff];
  101. var o = [0, 0, 0, 0];
  102.  
  103. o[3] += m[3] * n[3];
  104. o[2] += o[3] >>> 16;
  105. o[3] &= 0xffff;
  106.  
  107. o[2] += m[2] * n[3];
  108. o[1] += o[2] >>> 16;
  109. o[2] &= 0xffff;
  110.  
  111. o[2] += m[3] * n[2];
  112. o[1] += o[2] >>> 16;
  113. o[2] &= 0xffff;
  114.  
  115. o[1] += m[1] * n[3];
  116. o[0] += o[1] >>> 16;
  117. o[1] &= 0xffff;
  118.  
  119. o[1] += m[2] * n[2];
  120. o[0] += o[1] >>> 16;
  121. o[1] &= 0xffff;
  122.  
  123. o[1] += m[3] * n[1];
  124. o[0] += o[1] >>> 16;
  125. o[1] &= 0xffff;
  126.  
  127. o[0] += (m[0] * n[3]) + (m[1] * n[2]) + (m[2] * n[1]) + (m[3] * n[0]);
  128. o[0] &= 0xffff;
  129.  
  130. return [(o[0] << 16) | o[1], (o[2] << 16) | o[3]];
  131. }
  132.  
  133.  
  134. function _x64Rotl(m, n) {
  135. //
  136. // Given a 64bit int (as an array of two 32bit ints) and an int
  137. // representing a number of bit positions, returns the 64bit int (as an
  138. // array of two 32bit ints) rotated left by that number of positions.
  139. //
  140.  
  141. n %= 64;
  142.  
  143. if (n === 32) {
  144. return [m[1], m[0]];
  145. }
  146.  
  147. else if (n < 32) {
  148. return [(m[0] << n) | (m[1] >>> (32 - n)), (m[1] << n) | (m[0] >>> (32 - n))];
  149. }
  150.  
  151. else {
  152. n -= 32;
  153. return [(m[1] << n) | (m[0] >>> (32 - n)), (m[0] << n) | (m[1] >>> (32 - n))];
  154. }
  155. }
  156.  
  157.  
  158. function _x64LeftShift(m, n) {
  159. //
  160. // Given a 64bit int (as an array of two 32bit ints) and an int
  161. // representing a number of bit positions, returns the 64bit int (as an
  162. // array of two 32bit ints) shifted left by that number of positions.
  163. //
  164.  
  165. n %= 64;
  166.  
  167. if (n === 0) {
  168. return m;
  169. }
  170.  
  171. else if (n < 32) {
  172. return [(m[0] << n) | (m[1] >>> (32 - n)), m[1] << n];
  173. }
  174.  
  175. else {
  176. return [m[1] << (n - 32), 0];
  177. }
  178. }
  179.  
  180.  
  181. function _x64Xor(m, n) {
  182. //
  183. // Given two 64bit ints (as an array of two 32bit ints) returns the two
  184. // xored together as a 64bit int (as an array of two 32bit ints).
  185. //
  186.  
  187. return [m[0] ^ n[0], m[1] ^ n[1]];
  188. }
  189.  
  190.  
  191. function _x64Fmix(h) {
  192. //
  193. // Given a block, returns murmurHash3's final x64 mix of that block.
  194. // (`[0, h[0] >>> 1]` is a 33 bit unsigned right shift. This is the
  195. // only place where we need to right shift 64bit ints.)
  196. //
  197.  
  198. h = _x64Xor(h, [0, h[0] >>> 1]);
  199. h = _x64Multiply(h, [0xff51afd7, 0xed558ccd]);
  200. h = _x64Xor(h, [0, h[0] >>> 1]);
  201. h = _x64Multiply(h, [0xc4ceb9fe, 0x1a85ec53]);
  202. h = _x64Xor(h, [0, h[0] >>> 1]);
  203.  
  204. return h;
  205. }
  206.  
  207.  
  208.  
  209.  
  210. // PUBLIC FUNCTIONS
  211. // ----------------
  212.  
  213. library.x86.hash32 = function (key, seed) {
  214. //
  215. // Given a string and an optional seed as an int, returns a 32 bit hash
  216. // using the x86 flavor of MurmurHash3, as an unsigned int.
  217. //
  218.  
  219. key = key || '';
  220. seed = seed || 0;
  221.  
  222. var remainder = key.length % 4;
  223. var bytes = key.length - remainder;
  224.  
  225. var h1 = seed;
  226.  
  227. var k1 = 0;
  228.  
  229. var c1 = 0xcc9e2d51;
  230. var c2 = 0x1b873593;
  231.  
  232. for (var i = 0; i < bytes; i = i + 4) {
  233. k1 = ((key.charCodeAt(i) & 0xff)) | ((key.charCodeAt(i + 1) & 0xff) << 8) | ((key.charCodeAt(i + 2) & 0xff) << 16) | ((key.charCodeAt(i + 3) & 0xff) << 24);
  234.  
  235. k1 = _x86Multiply(k1, c1);
  236. k1 = _x86Rotl(k1, 15);
  237. k1 = _x86Multiply(k1, c2);
  238.  
  239. h1 ^= k1;
  240. h1 = _x86Rotl(h1, 13);
  241. h1 = _x86Multiply(h1, 5) + 0xe6546b64;
  242. }
  243.  
  244. k1 = 0;
  245.  
  246. switch (remainder) {
  247. case 3:
  248. k1 ^= (key.charCodeAt(i + 2) & 0xff) << 16;
  249.  
  250. case 2:
  251. k1 ^= (key.charCodeAt(i + 1) & 0xff) << 8;
  252.  
  253. case 1:
  254. k1 ^= (key.charCodeAt(i) & 0xff);
  255. k1 = _x86Multiply(k1, c1);
  256. k1 = _x86Rotl(k1, 15);
  257. k1 = _x86Multiply(k1, c2);
  258. h1 ^= k1;
  259. }
  260.  
  261. h1 ^= key.length;
  262. h1 = _x86Fmix(h1);
  263.  
  264. return h1 >>> 0;
  265. };
  266.  
  267.  
  268. library.x86.hash128 = function (key, seed) {
  269. //
  270. // Given a string and an optional seed as an int, returns a 128 bit
  271. // hash using the x86 flavor of MurmurHash3, as an unsigned hex.
  272. //
  273.  
  274. key = key || '';
  275. seed = seed || 0;
  276.  
  277. var remainder = key.length % 16;
  278. var bytes = key.length - remainder;
  279.  
  280. var h1 = seed;
  281. var h2 = seed;
  282. var h3 = seed;
  283. var h4 = seed;
  284.  
  285. var k1 = 0;
  286. var k2 = 0;
  287. var k3 = 0;
  288. var k4 = 0;
  289.  
  290. var c1 = 0x239b961b;
  291. var c2 = 0xab0e9789;
  292. var c3 = 0x38b34ae5;
  293. var c4 = 0xa1e38b93;
  294.  
  295. for (var i = 0; i < bytes; i = i + 16) {
  296. k1 = ((key.charCodeAt(i) & 0xff)) | ((key.charCodeAt(i + 1) & 0xff) << 8) | ((key.charCodeAt(i + 2) & 0xff) << 16) | ((key.charCodeAt(i + 3) & 0xff) << 24);
  297. k2 = ((key.charCodeAt(i + 4) & 0xff)) | ((key.charCodeAt(i + 5) & 0xff) << 8) | ((key.charCodeAt(i + 6) & 0xff) << 16) | ((key.charCodeAt(i + 7) & 0xff) << 24);
  298. k3 = ((key.charCodeAt(i + 8) & 0xff)) | ((key.charCodeAt(i + 9) & 0xff) << 8) | ((key.charCodeAt(i + 10) & 0xff) << 16) | ((key.charCodeAt(i + 11) & 0xff) << 24);
  299. k4 = ((key.charCodeAt(i + 12) & 0xff)) | ((key.charCodeAt(i + 13) & 0xff) << 8) | ((key.charCodeAt(i + 14) & 0xff) << 16) | ((key.charCodeAt(i + 15) & 0xff) << 24);
  300.  
  301. k1 = _x86Multiply(k1, c1);
  302. k1 = _x86Rotl(k1, 15);
  303. k1 = _x86Multiply(k1, c2);
  304. h1 ^= k1;
  305.  
  306. h1 = _x86Rotl(h1, 19);
  307. h1 += h2;
  308. h1 = _x86Multiply(h1, 5) + 0x561ccd1b;
  309.  
  310. k2 = _x86Multiply(k2, c2);
  311. k2 = _x86Rotl(k2, 16);
  312. k2 = _x86Multiply(k2, c3);
  313. h2 ^= k2;
  314.  
  315. h2 = _x86Rotl(h2, 17);
  316. h2 += h3;
  317. h2 = _x86Multiply(h2, 5) + 0x0bcaa747;
  318.  
  319. k3 = _x86Multiply(k3, c3);
  320. k3 = _x86Rotl(k3, 17);
  321. k3 = _x86Multiply(k3, c4);
  322. h3 ^= k3;
  323.  
  324. h3 = _x86Rotl(h3, 15);
  325. h3 += h4;
  326. h3 = _x86Multiply(h3, 5) + 0x96cd1c35;
  327.  
  328. k4 = _x86Multiply(k4, c4);
  329. k4 = _x86Rotl(k4, 18);
  330. k4 = _x86Multiply(k4, c1);
  331. h4 ^= k4;
  332.  
  333. h4 = _x86Rotl(h4, 13);
  334. h4 += h1;
  335. h4 = _x86Multiply(h4, 5) + 0x32ac3b17;
  336. }
  337.  
  338. k1 = 0;
  339. k2 = 0;
  340. k3 = 0;
  341. k4 = 0;
  342.  
  343. switch (remainder) {
  344. case 15:
  345. k4 ^= key.charCodeAt(i + 14) << 16;
  346.  
  347. case 14:
  348. k4 ^= key.charCodeAt(i + 13) << 8;
  349.  
  350. case 13:
  351. k4 ^= key.charCodeAt(i + 12);
  352. k4 = _x86Multiply(k4, c4);
  353. k4 = _x86Rotl(k4, 18);
  354. k4 = _x86Multiply(k4, c1);
  355. h4 ^= k4;
  356.  
  357. case 12:
  358. k3 ^= key.charCodeAt(i + 11) << 24;
  359.  
  360. case 11:
  361. k3 ^= key.charCodeAt(i + 10) << 16;
  362.  
  363. case 10:
  364. k3 ^= key.charCodeAt(i + 9) << 8;
  365.  
  366. case 9:
  367. k3 ^= key.charCodeAt(i + 8);
  368. k3 = _x86Multiply(k3, c3);
  369. k3 = _x86Rotl(k3, 17);
  370. k3 = _x86Multiply(k3, c4);
  371. h3 ^= k3;
  372.  
  373. case 8:
  374. k2 ^= key.charCodeAt(i + 7) << 24;
  375.  
  376. case 7:
  377. k2 ^= key.charCodeAt(i + 6) << 16;
  378.  
  379. case 6:
  380. k2 ^= key.charCodeAt(i + 5) << 8;
  381.  
  382. case 5:
  383. k2 ^= key.charCodeAt(i + 4);
  384. k2 = _x86Multiply(k2, c2);
  385. k2 = _x86Rotl(k2, 16);
  386. k2 = _x86Multiply(k2, c3);
  387. h2 ^= k2;
  388.  
  389. case 4:
  390. k1 ^= key.charCodeAt(i + 3) << 24;
  391.  
  392. case 3:
  393. k1 ^= key.charCodeAt(i + 2) << 16;
  394.  
  395. case 2:
  396. k1 ^= key.charCodeAt(i + 1) << 8;
  397.  
  398. case 1:
  399. k1 ^= key.charCodeAt(i);
  400. k1 = _x86Multiply(k1, c1);
  401. k1 = _x86Rotl(k1, 15);
  402. k1 = _x86Multiply(k1, c2);
  403. h1 ^= k1;
  404. }
  405.  
  406. h1 ^= key.length;
  407. h2 ^= key.length;
  408. h3 ^= key.length;
  409. h4 ^= key.length;
  410.  
  411. h1 += h2;
  412. h1 += h3;
  413. h1 += h4;
  414. h2 += h1;
  415. h3 += h1;
  416. h4 += h1;
  417.  
  418. h1 = _x86Fmix(h1);
  419. h2 = _x86Fmix(h2);
  420. h3 = _x86Fmix(h3);
  421. h4 = _x86Fmix(h4);
  422.  
  423. h1 += h2;
  424. h1 += h3;
  425. h1 += h4;
  426. h2 += h1;
  427. h3 += h1;
  428. h4 += h1;
  429.  
  430. return ("00000000" + (h1 >>> 0).toString(16)).slice(-8) + ("00000000" + (h2 >>> 0).toString(16)).slice(-8) + ("00000000" + (h3 >>> 0).toString(16)).slice(-8) + ("00000000" + (h4 >>> 0).toString(16)).slice(-8);
  431. };
  432.  
  433.  
  434. library.x64.hash128 = function (key, seed) {
  435. //
  436. // Given a string and an optional seed as an int, returns a 128 bit
  437. // hash using the x64 flavor of MurmurHash3, as an unsigned hex.
  438. //
  439.  
  440. key = key || '';
  441. seed = seed || 0;
  442.  
  443. var remainder = key.length % 16;
  444. var bytes = key.length - remainder;
  445.  
  446. var h1 = [0, seed];
  447. var h2 = [0, seed];
  448.  
  449. var k1 = [0, 0];
  450. var k2 = [0, 0];
  451.  
  452. var c1 = [0x87c37b91, 0x114253d5];
  453. var c2 = [0x4cf5ad43, 0x2745937f];
  454.  
  455. for (var i = 0; i < bytes; i = i + 16) {
  456. k1 = [((key.charCodeAt(i + 4) & 0xff)) | ((key.charCodeAt(i + 5) & 0xff) << 8) | ((key.charCodeAt(i + 6) & 0xff) << 16) | ((key.charCodeAt(i + 7) & 0xff) << 24), ((key.charCodeAt(i) & 0xff)) | ((key.charCodeAt(i + 1) & 0xff) << 8) | ((key.charCodeAt(i + 2) & 0xff) << 16) | ((key.charCodeAt(i + 3) & 0xff) << 24)];
  457. k2 = [((key.charCodeAt(i + 12) & 0xff)) | ((key.charCodeAt(i + 13) & 0xff) << 8) | ((key.charCodeAt(i + 14) & 0xff) << 16) | ((key.charCodeAt(i + 15) & 0xff) << 24), ((key.charCodeAt(i + 8) & 0xff)) | ((key.charCodeAt(i + 9) & 0xff) << 8) | ((key.charCodeAt(i + 10) & 0xff) << 16) | ((key.charCodeAt(i + 11) & 0xff) << 24)];
  458.  
  459. k1 = _x64Multiply(k1, c1);
  460. k1 = _x64Rotl(k1, 31);
  461. k1 = _x64Multiply(k1, c2);
  462. h1 = _x64Xor(h1, k1);
  463.  
  464. h1 = _x64Rotl(h1, 27);
  465. h1 = _x64Add(h1, h2);
  466. h1 = _x64Add(_x64Multiply(h1, [0, 5]), [0, 0x52dce729]);
  467.  
  468. k2 = _x64Multiply(k2, c2);
  469. k2 = _x64Rotl(k2, 33);
  470. k2 = _x64Multiply(k2, c1);
  471. h2 = _x64Xor(h2, k2);
  472.  
  473. h2 = _x64Rotl(h2, 31);
  474. h2 = _x64Add(h2, h1);
  475. h2 = _x64Add(_x64Multiply(h2, [0, 5]), [0, 0x38495ab5]);
  476. }
  477.  
  478. k1 = [0, 0];
  479. k2 = [0, 0];
  480.  
  481. switch(remainder) {
  482. case 15:
  483. k2 = _x64Xor(k2, _x64LeftShift([0, key.charCodeAt(i + 14)], 48));
  484.  
  485. case 14:
  486. k2 = _x64Xor(k2, _x64LeftShift([0, key.charCodeAt(i + 13)], 40));
  487.  
  488. case 13:
  489. k2 = _x64Xor(k2, _x64LeftShift([0, key.charCodeAt(i + 12)], 32));
  490.  
  491. case 12:
  492. k2 = _x64Xor(k2, _x64LeftShift([0, key.charCodeAt(i + 11)], 24));
  493.  
  494. case 11:
  495. k2 = _x64Xor(k2, _x64LeftShift([0, key.charCodeAt(i + 10)], 16));
  496.  
  497. case 10:
  498. k2 = _x64Xor(k2, _x64LeftShift([0, key.charCodeAt(i + 9)], 8));
  499.  
  500. case 9:
  501. k2 = _x64Xor(k2, [0, key.charCodeAt(i + 8)]);
  502. k2 = _x64Multiply(k2, c2);
  503. k2 = _x64Rotl(k2, 33);
  504. k2 = _x64Multiply(k2, c1);
  505. h2 = _x64Xor(h2, k2);
  506.  
  507. case 8:
  508. k1 = _x64Xor(k1, _x64LeftShift([0, key.charCodeAt(i + 7)], 56));
  509.  
  510. case 7:
  511. k1 = _x64Xor(k1, _x64LeftShift([0, key.charCodeAt(i + 6)], 48));
  512.  
  513. case 6:
  514. k1 = _x64Xor(k1, _x64LeftShift([0, key.charCodeAt(i + 5)], 40));
  515.  
  516. case 5:
  517. k1 = _x64Xor(k1, _x64LeftShift([0, key.charCodeAt(i + 4)], 32));
  518.  
  519. case 4:
  520. k1 = _x64Xor(k1, _x64LeftShift([0, key.charCodeAt(i + 3)], 24));
  521.  
  522. case 3:
  523. k1 = _x64Xor(k1, _x64LeftShift([0, key.charCodeAt(i + 2)], 16));
  524.  
  525. case 2:
  526. k1 = _x64Xor(k1, _x64LeftShift([0, key.charCodeAt(i + 1)], 8));
  527.  
  528. case 1:
  529. k1 = _x64Xor(k1, [0, key.charCodeAt(i)]);
  530. k1 = _x64Multiply(k1, c1);
  531. k1 = _x64Rotl(k1, 31);
  532. k1 = _x64Multiply(k1, c2);
  533. h1 = _x64Xor(h1, k1);
  534. }
  535.  
  536. h1 = _x64Xor(h1, [0, key.length]);
  537. h2 = _x64Xor(h2, [0, key.length]);
  538.  
  539. h1 = _x64Add(h1, h2);
  540. h2 = _x64Add(h2, h1);
  541.  
  542. h1 = _x64Fmix(h1);
  543. h2 = _x64Fmix(h2);
  544.  
  545. h1 = _x64Add(h1, h2);
  546. h2 = _x64Add(h2, h1);
  547.  
  548. return ("00000000" + (h1[0] >>> 0).toString(16)).slice(-8) + ("00000000" + (h1[1] >>> 0).toString(16)).slice(-8) + ("00000000" + (h2[0] >>> 0).toString(16)).slice(-8) + ("00000000" + (h2[1] >>> 0).toString(16)).slice(-8);
  549. };
  550.  
  551.  
  552.  
  553.  
  554. // INITIALIZATION
  555. // --------------
  556.  
  557. // Export murmurHash3 for CommonJS, either as an AMD module or just as part
  558. // of the global object.
  559. if (typeof exports !== 'undefined') {
  560. if (typeof module !== 'undefined' && module.exports) {
  561. exports = module.exports = library;
  562. }
  563.  
  564. exports.murmurHash3 = library;
  565. }
  566.  
  567. else if (typeof define === 'function' && define.amd) {
  568. define([], function() {
  569. return library;
  570. });
  571. }
  572.  
  573. else {
  574. // Use murmurHash3.noConflict to restore `murmurHash3` back to its
  575. // original value. Returns a reference to the library object, to allow
  576. // it to be used under a different name.
  577. library._murmurHash3 = root.murmurHash3
  578.  
  579. library.noConflict = function () {
  580. root.murmurHash3 = library._murmurHash3;
  581. library._murmurHash3 = undefined;
  582. library.noConflict = undefined;
  583.  
  584. return library;
  585. };
  586.  
  587. root.murmurHash3 = library;
  588. }
  589. })(this);
Success #stdin #stdout 0.97s 58608KB
stdin
1-sky-400
stdout
Standard output is empty