|
摘自PHP的HASH算法实现(4) pht->size_index = i; break; } } if (i == COUNTS_OF_SIZE_TABLE) { size = size_table[COUNTS_OF_SIZE_TABLE - 1]; pht->size_index = COUNTS_OF_SIZE_TABLE - 1; } pht->buckets = (LPHASHBUCKET *)calloc(size, sizeof(LPHASHBUCKET)); if (!pht->buckets) { return -1; } pht->hash = hash? hash: hashpjw; pht->elements = 0; pht->head = 0; pht->p = 0; pht->tail = 0; pht->table_size = size; return 0; } int hash_entry(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) { if (!memcmp(p->key, key, key_length)) {
|