1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-15 11:41:13 +03:00

Use Knuth multiplicative hashing for the symbol table.

FossilOrigin-Name: cc29ddd6be60bdbf107f285c9eb57d5896ebca2d
This commit is contained in:
drh
2016-09-28 20:42:31 +00:00
parent 5e769a50ad
commit 5f33eaa6a4
3 changed files with 12 additions and 8 deletions

View File

@@ -56,7 +56,11 @@ static unsigned int strHash(const char *z){
unsigned int h = 0;
unsigned char c;
while( (c = (unsigned char)*z++)!=0 ){ /*OPTIMIZATION-IF-TRUE*/
h = (h<<3) ^ h ^ sqlite3UpperToLower[c];
/* Knuth multiplicative hashing. (Sorting & Searching, p. 510).
** 0x9e3779b1 is 2654435761 which is the closest prime number to
** (2**32)*golden_ratio, where golden_ratio = (sqrt(5) - 1)/2. */
h += sqlite3UpperToLower[c];
h *= 0x9e3779b1;
}
return h;
}