|
摘自PHP的HASH算法实现(3) p->conflict_previous->conflict_next = p; } pht->buckets[index] = p; } return 0; } static int hash_do_resize(LPHASHTABLE pht) { LPHASHBUCKET *pp; if (pht->size_index < (unsigned int)COUNTS_OF_SIZE_TABLE - 1) { pp = (LPHASHBUCKET *)realloc(pht->buckets, size_table[pht->size_index + 1] * sizeof(LPHASHBUCKET)); if (pp) { pht->buckets = pp; pht->size_index++; pht->table_size = size_table[pht->size_index]; hash_do_rehash(pht); return 0; } return -1; } return 0; } int hash_create(LPHASHTABLE pht, unsigned int size, hash_func_t hash) { int i; for (i = 0; i < COUNTS_OF_SIZE_TABLE; ++i) { if (size <= size_table[i]) { size = size_table[i];
|