darling-libobjc2/string_hash.h
theraven bdf97cf64e Added hopscotch table implementation and rewrote the class table to use it. This is done so that the class table and protocol tables can share the same code (currently there is no protocol table).
Note that concurrent resizing has not yet been implemented.  That means that there is a hard limit on the number of classes that can be loaded.  This is currently set to quite a small number for testing, to stress the hash table.  If you're experiencing problems as a result, then please let me know and I will increase it.
2010-01-07 18:22:13 +00:00

33 lines
472 B
C

#include <string.h>
#include <stdint.h>
/**
* Efficient string hash function.
*/
static uint32_t string_hash(const char *str)
{
uint32_t hash = 0;
int32_t c;
while ((c = *str++))
{
hash = c + (hash << 6) + (hash << 16) - hash;
}
return hash;
}
/**
* Test two strings for equality.
*/
static int string_compare(const char *str1, const char *str2)
{
if (str1 == str2)
{
return 1;
}
if (str2 == NULL)
{
return 0;
}
return strcmp(str1, str2) == 0;
}