Closed YjyJeff closed 4 months ago
Note that due to the logic here, this growth will only happen once. After that it will always perform an in-place rehash which will not allocate.
Note that due to the logic here, this growth will only happen once. After that it will always perform an in-place rehash which will not allocate.
I got the same conclusion after reading the code. So, the design of the hashbrown caused that we can not avoid the in-place rehashing, right?
If you reserve space for CAP * 2
then it should never grow.
In some cases, we know the capacity of the hash table, for example, we want to store the fixed number of elements in the cache. Therefore, we allocate the hash table with
with_capacity(CAP)
method. When the cache is full, we need to delete the entry and insert the new entry into it. In ideal, the hash table should never grow.However, the hash table grows... We can try the following code to verify it, the code will panic at
try_insert_no_grow
The reason why it happens is that: the erase function does not increase the
growth_left
. Can we accomplish the above case without growing?Thanks in advance