-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
90 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,62 +137,14 @@ export function searchForWorkspaceRoot( | |
return searchForWorkspaceRoot(dir, root) | ||
} | ||
|
||
/* eslint-disable no-fallthrough */ | ||
|
||
/** | ||
* JS Implementation of MurmurHash2 | ||
* | ||
* @author <a href="mailto:[email protected]">Gary Court</a> | ||
* @see http://github.com/garycourt/murmurhash-js | ||
* @author <a href="mailto:[email protected]">Austin Appleby</a> | ||
* @see http://sites.google.com/site/murmurhash/ | ||
* | ||
* @param {string} str ASCII only | ||
* @param {number} seed Positive integer only | ||
* @return {number} 32-bit positive integer hash | ||
*/ | ||
function murmurhash2_32_gc(str: string, seed: number = 0) { | ||
let l = str.length | ||
let h = seed ^ l | ||
let i = 0 | ||
let k | ||
|
||
while (l >= 4) { | ||
k = (str.charCodeAt(i) & 0xff) | | ||
((str.charCodeAt(++i) & 0xff) << 8) | | ||
((str.charCodeAt(++i) & 0xff) << 16) | | ||
((str.charCodeAt(++i) & 0xff) << 24) | ||
|
||
k = (k & 0xffff) * 0x5bd1e995 + ((((k >>> 16) * 0x5bd1e995) & 0xffff) << 16) | ||
k ^= k >>> 24 | ||
k = (k & 0xffff) * 0x5bd1e995 + ((((k >>> 16) * 0x5bd1e995) & 0xffff) << 16) | ||
|
||
h = ((h & 0xffff) * 0x5bd1e995 + | ||
((((h >>> 16) * 0x5bd1e995) & 0xffff) << 16)) ^ | ||
k | ||
|
||
l -= 4 // eslint-disable-next-line stylistic/semi | ||
;++i | ||
} | ||
|
||
switch (l) { | ||
case 3: | ||
h ^= (str.charCodeAt(i + 2) & 0xff) << 16 | ||
case 2: | ||
h ^= (str.charCodeAt(i + 1) & 0xff) << 8 | ||
case 1: | ||
h ^= str.charCodeAt(i) & 0xff | ||
h = (h & 0xffff) * 0x5bd1e995 + | ||
((((h >>> 16) * 0x5bd1e995) & 0xffff) << 16) | ||
export function hash(str: string) { | ||
let i | ||
let l | ||
let hval = 0x811C9DC5 | ||
|
||
for (i = 0, l = str.length; i < l; i++) { | ||
hval ^= str.charCodeAt(i) | ||
hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24) | ||
} | ||
|
||
h ^= h >>> 13 | ||
h = (h & 0xffff) * 0x5bd1e995 + ((((h >>> 16) * 0x5bd1e995) & 0xffff) << 16) | ||
h ^= h >>> 15 | ||
|
||
return h >>> 0 | ||
} | ||
|
||
export function hash(str: string): string { | ||
return murmurhash2_32_gc(str, 1).toString(36) | ||
return (`00000${(hval >>> 0).toString(36)}`).slice(-6) | ||
} |