|
摘自PHP的HASH算法实现(2) {5, 11, 19, 53, 107, 223, 463, 983, 1979, 3907, 7963, 16229, 32531, 65407, 130987, 262237, 524521, 1048793, 2097397, 41941 03, 8388857, 16777447, 33554201, 67108961, 134217487, 268435697, 536870683, 1073741621, 2147483399}; #define COUNTS_OF_SIZE_TABLE (sizeof(size_table) / sizeof(size_table[0])) static unsigned long hashpjw(char *key, unsigned int key_length) { unsigned long h, g; char *p; h = 0; p = key + key_length; while (key < p) { h = (h << 4) + *key++; if ((g = (h & 0xF0000000))) { h = h ^ (g >> 24); h = h ^ g; } } return h; } static int hash_do_rehash(LPHASHTABLE pht) { LPHASHBUCKET p; unsigned int index; memset(pht->buckets, 0, sizeof(LPHASHBUCKET) * size_table[pht->size_index]); for (p = pht->head; p; p = p->next) { index = p->h % pht->table_size; p->conflict_next = 0; p->conflict_previous = pht->buckets[index]; if (p->conflict_previous) {
|