-
-
Save amankharwal/e1d3291a9b01b612ca8f5ada74164fd1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class hashtable: | |
def __init__(self, items): | |
self.bucket_size = len(items) | |
self.buckets = [[] for i in range(self.bucket_size)] | |
self.assign_buckets(items) | |
def assign_buckets(self, items): | |
for key, value in elements: | |
hash_value = hash(key) | |
index = hash_value % self.bucket_size | |
self.buckets[index].append((key, value)) | |
def get_value(self, input_keys): | |
hash_value = hash(input_keys) | |
index = hash_value % self.bucket_size | |
bucket = self.buckets[index] | |
for key, value in bucket: | |
if key == input_keys: | |
return(value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment