Question: I need help building two methods for a program that builds a hash table. I have attached what I have already built below. class intHash(object):
I need help building two methods for a program that builds a hash table.

I have attached what I have already built below. class intHash(object): """A hash table with integer keys""" def __init__(self, numBuckets): """Create an empty table with numBuckets buckets""" self.buckets = [] self.numBuckets = numBuckets for i in range(numBuckets): self.buckets.append([]) def addEntry(self, key, value): """Assumes key an int. Adds an entry.""" hashBucket = self.buckets[key%self.numBuckets] hashBucket.append((key, value)) def getValue(self, key): """Assumes key an int. Returns value associated with key""" hashBucket = self.buckets[key%self.numBuckets] values=[] for e in hashBucket: if e[0] == key: values.append(e[1]) return values def __str__(self): result = '{' for b in self.buckets: for e in b: result = result + str(e[0]) + ':' + str(e[1]) + ',' return result[:-1] + '}' #result[:-1] omits the last comma def findValue(self, value, hashkey): """Returns '(value) Prensent' if its found in the has table using the key hashkey and returns '(value) Not Found' if value is not in the table""" if valpresent: print(str(hashkey) + " present") else: print(str(hashkey) + " not present") #A Possible integer key for names def getNameKey(name): """returns the hashkey for a string name""" key=0 namelist=list(name) for letter in name: if letter != " " and letter !='.': key=key+ord(letter) return key name = intHash(10) infile = open("onlyNames.txt", 'r') for line in infile: key = getNameKey(line[:-1]) name.addEntry(key,line) infile.close()
Write a findValue method for intHash as specified below. def findValue(self, value, hashkey): """Returns (value) Present' if is found in the hash table using the key hashkey and returns '(value) Not Found' if value is not in the table""" Write a deleteValue method for intHash as specified below: def deleteValue(self, value, hashkey): n"Deletes value from the hash table using the key function hashkey
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
