|
摘自PHP的HASH算法实现(8) { pht->tail = p->previous; } --pht->elements; free(p); return 0; } } return -1; } int hash_update(LPHASHTABLE pht, char *key, unsigned int key_length, void *data) { 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)) { p->data = data; return 0; } } return -1; }
int hash_destroy(LPHASHTABLE pht) { LPHASHBUCKET p, q; p = pht->head; while (p) {
|