source: trip-planner-front/node_modules/webpack/lib/util/numberHash.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.0 KB
Line 
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8const SAFE_LIMIT = 0x80000000;
9const SAFE_PART = SAFE_LIMIT - 1;
10const COUNT = 4;
11const arr = [0, 0, 0, 0, 0];
12const primes = [3, 7, 17, 19];
13
14module.exports = (str, range) => {
15 arr.fill(0);
16 for (let i = 0; i < str.length; i++) {
17 const c = str.charCodeAt(i);
18 for (let j = 0; j < COUNT; j++) {
19 const p = (j + COUNT - 1) % COUNT;
20 arr[j] = (arr[j] + c * primes[j] + arr[p]) & SAFE_PART;
21 }
22 for (let j = 0; j < COUNT; j++) {
23 const q = arr[j] % COUNT;
24 arr[j] = arr[j] ^ (arr[q] >> 1);
25 }
26 }
27 if (range <= SAFE_PART) {
28 let sum = 0;
29 for (let j = 0; j < COUNT; j++) {
30 sum = (sum + arr[j]) % range;
31 }
32 return sum;
33 } else {
34 let sum1 = 0;
35 let sum2 = 0;
36 const rangeExt = Math.floor(range / SAFE_LIMIT);
37 for (let j = 0; j < COUNT; j += 2) {
38 sum1 = (sum1 + arr[j]) & SAFE_PART;
39 }
40 for (let j = 1; j < COUNT; j += 2) {
41 sum2 = (sum2 + arr[j]) % rangeExt;
42 }
43 return (sum2 * SAFE_LIMIT + sum1) % range;
44 }
45};
Note: See TracBrowser for help on using the repository browser.