重新散列哈希表

时间:2017-01-21 23:05:37

标签: c hashmap hashtable

当我调试时,我发现在临时散列表中 - 'hashtable2'没有插入任何元素。哈希表代码的所有其他部分都有效。

我不确定为什么没有值插入hashtable2

void rehash(struct HashTable* hashTable, int keySize)
{
    int i;
    struct HashElement* current;
    int i2 = 0;
    struct List* word;
    struct List* key;
    struct HashTable* hashTable2 = hashTableConstructor(33524, keySize);

    hashTable->keySize = keySize; 

    for(i=0; i<hashTable->numBuckets; i++) //for every bucket
    {
        current = hashTable->buckets[i];

        //'walk' the linked list of HashElements in the bucket
        while( current != NULL )
        { //till the end of hash table
            word = listConstructor();
            key = listConstructor();
            word = current->value;

            for(i2 = 0; i2<keySize; i2++)
            {
                listAdd(key, tolower(getCharacter(word,i2)));
            }

            insert(hashTable2, word, key);
            listDestructor(key);
            listDestructor(word);
            current = current->next;
        }

    }



    hashTableDestructor(hashTable);


    hashTable = hashTableConstructor(33524, keySize);
    hashTable = hashTable2;

}

0 个答案:

没有答案