|
摘自PHP的HASH算法实现(6) { unsigned long h; unsigned int index; LPHASHBUCKET p; h = pht->hash(key, key_length); index = h % pht->table_size; for (p = pht->buckets[index]; p; p = p->conflict_previous) { if (p->h == h && p->key_length == key_length && !memcmp(p->key, key, key_length)) { *data = p->data; return 0; } } return -1; } int hash_remove(LPHASHTABLE pht, char *key, unsigned int key_length) { unsigned long h; unsigned int index; LPHASHBUCKET p; h = pht->hash(key, key_length); index = h % pht->table_size; for (p = pht->buckets[index]; p; p = p->conflict_previous) { if (p->h == h && p->key_length == key_length && !memcmp(p->key, key, key_length)) { if (p->conflict_previous) { p->conflict_previous->conflict_next = p->conflict_next;
|