mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 10:38:59 +01:00
17 lines
727 B
TypeScript
17 lines
727 B
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
function numberHash(val: number, initialHashVal: number): number {
|
|
return (((initialHashVal << 5) - initialHashVal) + val) | 0; // hashVal * 31 + ch, keep as int32
|
|
}
|
|
|
|
export function stringHash(s: string) {
|
|
let hashVal = numberHash(149417, 0);
|
|
for (let i = 0, length = s.length; i < length; i++) {
|
|
hashVal = numberHash(s.charCodeAt(i), hashVal);
|
|
}
|
|
return hashVal;
|
|
}
|