mirror of
https://github.com/w23/xash3d-fwgs
synced 2024-12-14 21:20:26 +01:00
public: crclib: optimize COM_HashKey, implement typical djb hashing as this function is used for hashtables with string lookup
This commit is contained in:
parent
f9205825b6
commit
5c1e06ae74
@ -457,10 +457,11 @@ returns hash key for string
|
|||||||
*/
|
*/
|
||||||
uint COM_HashKey( const char *string, uint hashSize )
|
uint COM_HashKey( const char *string, uint hashSize )
|
||||||
{
|
{
|
||||||
uint i, hashKey = 0;
|
int hashKey = 5381;
|
||||||
|
unsigned char i;
|
||||||
|
|
||||||
for( i = 0; string[i]; i++ )
|
while(( i = *string++ ))
|
||||||
hashKey = (hashKey + i) * 37 + Q_tolower( string[i] );
|
hashKey = ( hashKey << 5 ) + hashKey + ( i & 0xDF );
|
||||||
|
|
||||||
return (hashKey % hashSize);
|
return hashKey & ( hashSize - 1 );
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user