Closed bobzhang closed 1 month ago
The recent updates to the HashMap
module involve refactoring the remove
and shift_back
functions to streamline their loop structures using break
and continue
statements. Additionally, the grow
function has been optimized for better capacity adjustment by introducing a new variable for a more concise capacity calculation. These changes aim to enhance the efficiency and readability of the code.
File | Change Summary |
---|---|
hashmap/hashmap.mbt |
Simplified loop structures in the remove and shift_back functions; Optimized capacity adjustment in the grow function. |
sequenceDiagram
participant Client
participant HashMap
Client->>HashMap: remove(key)
loop Find the key
HashMap->>HashMap: Check each slot
alt Key found
HashMap->>HashMap: Remove key-value pair
HashMap->>HashMap: shift_back(start_index)
else Key not found
HashMap->>Client: Return
end
end
Client->>HashMap: grow()
HashMap->>HashMap: Calculate new_capacity
HashMap->>HashMap: Adjust capacity
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
Changes Missing Coverage | Covered Lines | Changed/Added Lines | % | ||
---|---|---|---|---|---|
hashmap/hashmap.mbt | 2 | 3 | 66.67% | ||
<!-- | Total: | 2 | 3 | 66.67% | --> |
Totals | |
---|---|
Change from base Build 1567: | 0.0% |
Covered Lines: | 2557 |
Relevant Lines: | 2870 |
@coderabbitai review
The 50% load factor will result in half of the space being wasted, maybe a higher load factor is better?
The 50% load factor will result in half of the space being wasted, maybe a higher load factor is better?
I am open to change the load factor later, rationale why I prefer 0.5 instead of higher values: