Skip to content
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

Update hash_map_chaining with linked feature #1665

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

DonglingMo
Copy link

This PR enhances the hash_map_chaining implementation by introducing linked insertion order tracking, making it functionally similar to LinkedHashMap. The key changes include:

  • Maintaining Insertion Order:
    Implemented a doubly linked list to preserve the order of key insertions.
    Added prev and next pointers to each entry to ensure efficient traversal.
  • Modified put() Method:
    When a new key-value pair is added, it is also linked at the end of the list to maintain order.
    If an existing key is updated, the insertion order remains unchanged.
  • Enhanced remove() Method:
    Supports safe removal from both the hash table and the linked list.
    Ensures that the insertion order remains valid after deletions.
  • Refactored Resizing (extendBuckets())
    When resizing occurs, the order of elements is preserved.
    The linked list structure is reconstructed after rehashing.

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.

1 participant