我设置了以下bucket条目结构和哈希表

typedef struct Hash_Entry
{
    struct Hash_Entry *next;
    void        *key_Data;
    unsigned    key_hash;
    char        key[5];
} Hash_Entry;

typedef struct Hash_Table
{
    struct Hash_Entry **bucketPtr;  /* Buckets in the table */
    int         size;       /* Actual size of array. */
    int         numEntries; /* Number of entries in the table. */
    int         mask;       /* Used to select bits for hashing. */
} Hash_Table;

我想为这个散列表创建一个数组(或一个动态数组),这样当我觉得表已满时,我可以创建另一个表,而不是重新调整它的大小

最佳答案

可以使用stdlib中的malloc创建数组

Hash_Table* array = (Hash_Table*)malloc(sizeof(Hash_Table) * 100);

当数组已满时,可以执行重新分配。
你可以看看:
Create dynamic sized array of user defined structure

关于c - 我如何在C中创建哈希表的动态数组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8848533/

10-11 23:07
查看更多