Skip to content

Overhaul hashmap_t functionalities #191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2025
Merged

Conversation

ChAoSUnItY
Copy link
Collaborator

@ChAoSUnItY ChAoSUnItY commented Apr 21, 2025

This patch fixes constracts of hashmap_t-related function, including:

  • hashmap_contains: Instead of delegates to result returned by hashmap_get, now shares similar logic to avoid bucket node value being NULL and treat as false.
  • hashmap_free: Now respects bucket node value's pointer, if it's already NULL, then hashmap won't free it.

Additionally, now hashmap_t is capable of rehashing its underlying bucket node array when load factor reaches 75%.

Closes #190.

Summary by Bito

This pull request enhances the `hashmap_t` functionalities by implementing a rehashing mechanism triggered at a 75% load factor, refining the `hashmap_contains` logic to avoid incorrect NULL returns, and updating `hashmap_free` for better memory management. These improvements optimize the performance and reliability of the hashmap, ensuring a more robust implementation.

Unit tests added: False

Estimated effort to review (1-5, lower is better): 2

@jserv jserv requested review from DrXiao and vacantron April 21, 2025 18:24
@ChAoSUnItY ChAoSUnItY force-pushed the fix/hashmap branch 2 times, most recently from 9059868 to 21e28d4 Compare April 22, 2025 06:20
This patch fixes constracts of hashmap_t-related function, including:

- hashmap_contains: Instead of delegates to result returned by
  hashmap_get, now shares similar logic to avoid bucket node value
  being NULL and treat as false.

Additionally, now hashmap_t is capable of rehashing its underlying
bucket node array when load factor reaches 75%.

Close sysprog21#190.
@jserv jserv merged commit d4bd334 into sysprog21:master Apr 22, 2025
6 checks passed
@jserv
Copy link
Collaborator

jserv commented Apr 22, 2025

Thank @ChAoSUnItY for contributing!

@ChAoSUnItY ChAoSUnItY deleted the fix/hashmap branch April 28, 2025 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rewrite contract of hashmap_t to be able to store NULL as value
3 participants