Update
This commit is contained in:
parent
e89e11a085
commit
8eee949aae
9 changed files with 1733 additions and 1732 deletions
10
hash.md
10
hash.md
|
@ -88,21 +88,21 @@ uint16_t hash(uint16_t n)
|
|||
}
|
||||
```
|
||||
|
||||
Here is a nice string hash, works even for short strings, all bits look pretty random: { Made by me. Tested this on my dataset of programming identifiers, on average there was one colliding pair of strings in 1000. ~drummyfish }
|
||||
Here is a simple string hash, works even for short strings, all bits look pretty random: { Made by me. Tested this on my dataset of 70000 programming identifiers, got no collisions. ~drummyfish }
|
||||
|
||||
```
|
||||
uint32_t strHash(const char *s)
|
||||
{
|
||||
uint32_t r = 21;
|
||||
uint32_t r = 11;
|
||||
|
||||
while (*s)
|
||||
{
|
||||
r = (r * 31) + *s;
|
||||
r = (r * 101) + *s;
|
||||
s++;
|
||||
}
|
||||
|
||||
r = r * 4451;
|
||||
r = ((r << 19) | (r >> 13)) * 5059;
|
||||
r = r * 251;
|
||||
r = ((r << 19) | (r >> 13)) * 113;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue