mirror of https://github.com/ErsatzTV/ErsatzTV.git
3 changed files with 33 additions and 1 deletions
@ -0,0 +1,23 @@ |
|||||||
|
namespace ErsatzTV.Core.Extensions; |
||||||
|
|
||||||
|
public static class StringExtensions |
||||||
|
{ |
||||||
|
public static int GetStableHashCode(this string str) |
||||||
|
{ |
||||||
|
unchecked |
||||||
|
{ |
||||||
|
int hash1 = 5381; |
||||||
|
int hash2 = hash1; |
||||||
|
|
||||||
|
for (int i = 0; i < str.Length && str[i] != '\0'; i += 2) |
||||||
|
{ |
||||||
|
hash1 = ((hash1 << 5) + hash1) ^ str[i]; |
||||||
|
if (i == str.Length - 1 || str[i + 1] == '\0') |
||||||
|
break; |
||||||
|
hash2 = ((hash2 << 5) + hash2) ^ str[i + 1]; |
||||||
|
} |
||||||
|
|
||||||
|
return hash1 + (hash2 * 1566083941); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue