Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 重灰化哈希表_C_Hashmap_Hashtable - Fatal编程技术网

C 重灰化哈希表

C 重灰化哈希表,c,hashmap,hashtable,C,Hashmap,Hashtable,调试时,我发现在临时哈希表--“hashtable2”中没有插入任何元素。哈希表代码的所有其他部分都可以工作 我不确定为什么要将no值插入hashtable2 void rehash(struct HashTable* hashTable, int keySize) { int i; struct HashElement* current; int i2 = 0; struct List* word; struct List* key; struc

调试时,我发现在临时哈希表--“hashtable2”中没有插入任何元素。哈希表代码的所有其他部分都可以工作

我不确定为什么要将no值插入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;

}
void-rehash(结构哈希表*HashTable,int-keySize)
{
int i;
结构哈希元素*当前;
int i2=0;
结构列表*word;
结构列表*键;
struct HashTable*hashTable2=hashTableConstructor(33524,keySize);
hashTable->keySize=keySize;
for(i=0;inumBuckets;i++)//对于每个桶
{
当前=哈希表->存储桶[i];
//“遍历”存储桶中哈希元素的链接列表
while(当前!=NULL)
{//直到哈希表的末尾
word=listConstructor();
key=listConstructor();
word=当前->值;
对于(i2=0;i2next;
}
}
哈希表析构函数(哈希表);
hashTable=hashTableConstructor(33524,keySize);
哈希表=哈希表2;
}

提示:
hashTable=hashTable2
;对函数的调用者来说没有任何意义。它是按值传递的,调用者保留该值。紧接着前面的一行是教科书中的基本内存泄漏。这不是Java或C#。而且,由于用于管理哈希表的绝大多数代码都不在本文档中post,我们没有什么可以使用的。那么我如何才能使用hashTable=hashTable2?我可以使用memcpy吗?在这个问题中确实没有足够的数据来知道如何正确执行您试图执行的操作。我们不知道hashTable、
HashElement
List
是什么。我们不知道它们是如何使用的我可以猜
*hashTable=*hashTable2;
可能会起作用,但您的内存管理需要仔细检查(我已经指出了一个漏洞),这个网站不是关于猜测,而是关于答案。为了提供一个结论性的答案,我们需要信息来得出有根据的结论,而目前我们还没有。请记住,我是一个初学者……如果列表是arraylist数据结构,还有什么其他可能的解决方案?