Growing a hash table
In our example, the hash table's size was set to 256. Obviously, as we add elements to the list, we begin to fill up the empty slots. At some point, all the slots will be filled up and the table will be full. To avoid this, we can grow the table when it is getting full.
To do this, we compare the size and the count. Remember that size held the total number of slots and count the number of those slots that contained elements? Well, if count equals size then we have filled up the table.
The hash table's load factor gives us an indication of how large a portion of the available slots are being used. It is defined as follows:
As the load factor approaches 1, we need to grow the table. In fact, we should do it before it gets ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access