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

Implement HashMap in Python #2149

Closed
wants to merge 1 commit into from
Closed

Implement HashMap in Python #2149

wants to merge 1 commit into from

Conversation

Coderx85
Copy link

@Coderx85 Coderx85 commented Oct 8, 2023

Pull Request

Related issue

Fixes #2126

PR checklist

Please check if your PR fulfills the following requirements:

  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

##Description
HashMap Implementation in Python

The provided Python code defines a custom HashMap class, allowing for the storage and retrieval of key-value pairs. The HashMap is initialized with a user-specified size, defaulting to 10 buckets.

Key features of this implementation include:

Hashing Function: The _hash method employs the built-in hash function to compute a hash value for a given key. This ensures even distribution of keys across buckets.

Insertion of Key-Value Pairs: The insert method inserts a new key-value pair or updates the value of an existing key. It utilizes the hash value to determine the appropriate bucket, then iterates through the bucket to handle potential collisions.

Retrieval of Values: The get method retrieves the value associated with a given key. It uses the hash value to locate the correct bucket, then iterates through the bucket to find the matching key.

Key Removal: The remove method allows for the deletion of a key-value pair based on the provided key. It utilizes the hash value to locate the correct bucket and subsequently iterates through the bucket to find and remove the key.

Error Handling: The implementation raises a KeyError if an attempt is made to retrieve or remove a non-existent key.

This HashMap implementation is designed for basic use cases and serves as a starting point for more sophisticated applications. It provides a clear foundation for understanding the underlying principles of HashMap data structures.

Thank you so much for contributing to Meilisearch!

@Coderx85 Coderx85 closed this Oct 15, 2023
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.

Design HashMap in Python
1 participant