1 | export function BKDRHash(str) {
|
2 | var seed = 131;
|
3 | var seed2 = 137;
|
4 | var hash = 0;
|
5 | str += 'x';
|
6 | var MAX_SAFE_INTEGER = Math.floor(9007199254740991 / seed2);
|
7 |
|
8 | for (var i = 0; i < str.length; i++) {
|
9 | if (hash > MAX_SAFE_INTEGER) {
|
10 | hash = Math.floor(hash / seed2);
|
11 | }
|
12 |
|
13 | hash = hash * seed + str.charCodeAt(i);
|
14 | }
|
15 |
|
16 | return hash;
|
17 | }
|
18 | export function djb2hash(str) {
|
19 | str = str.toString();
|
20 | var hash = 5381;
|
21 | var i = str.length;
|
22 |
|
23 | while (i) {
|
24 | hash = hash * 33 ^ str.charCodeAt(--i);
|
25 | }
|
26 |
|
27 | return hash >>> 0;
|
28 | }
|
29 |
|
\ | No newline at end of file |