Browse Source

public: crclib: optimize COM_HashKey, implement typical djb hashing as this function is used for hashtables with string lookup

pull/2/head
Alibek Omarov 1 year ago
parent
commit
5c1e06ae74
  1. 9
      public/crclib.c

9
public/crclib.c

@ -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…
Cancel
Save