r/C_Programming • • Aug 08 '26

Hash table

I am newbie and a beginner in c language. I would like to learn the hash table for my next semester.

I kindly ask for some help in this matter. I still struggle in the basics even using the ai models.

8 Upvotes

29 comments sorted by

View all comments

Show parent comment

3

u/thank_burdell Aug 08 '26

There are multiple ways to determine when you need to rehash, but as for how, your rehash should double the size of the array, make twice as many linked lists for it, and then iterate across the original to migrate them to the new. It’s an expensive operation so you don’t want to do it too often, and trying to guess the “right” size for your hashtable is a matter of testing your performance at various levels.

As for the function, it remains unchanged, you just look at one more bit from the hash it generates.