* 简单的字符串哈希函数 * @param str 要哈希的字符串 * @returns 哈希值
(str: string)
| 54 | * @returns 哈希值 |
| 55 | */ |
| 56 | private static hashCode(str: string): number { |
| 57 | let hash = 0; |
| 58 | if (str.length === 0) return hash; |
| 59 | |
| 60 | for (let i = 0; i < str.length; i++) { |
| 61 | const char = str.charCodeAt(i); |
| 62 | hash = ((hash << 5) - hash) + char; |
| 63 | hash = hash & hash; // 转换为32位整数 |
| 64 | } |
| 65 | |
| 66 | return hash; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * 检查是否为有效的高亮ID格式 |