Hash fonction just for fun.
This commit is contained in:
parent
70ae216122
commit
4e12ff1c94
11
src/util.c
11
src/util.c
@ -453,12 +453,15 @@ hash_t *hash_new(int options)
|
|||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Now we have a real hash, but we use only the last byte of it :p */
|
||||||
static unsigned char hash_func(char *pkey)
|
static unsigned char hash_func(char *pkey)
|
||||||
{
|
{
|
||||||
unsigned char i = 0;
|
char c;
|
||||||
while (*pkey)
|
unsigned long hash = 5381; /* 5381 & 0xff makes more sense */
|
||||||
i += (unsigned char)toupper(*pkey++);
|
|
||||||
return i;
|
while (c = *pkey++)
|
||||||
|
hash = ((hash << 5) + hash) ^ c;
|
||||||
|
return (unsigned char)hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hash_insert(hash_t *hash, char *key, void *ptr)
|
void hash_insert(hash_t *hash, char *key, void *ptr)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user