Use python to built hashtable data structure: class OrderedHashtable: def __init
ID: 3728421 • Letter: U
Question
Use python to built hashtable data structure:
class OrderedHashtable:
def __init__(self, index, next=None):
"""This class is used to create nodes in the singly linked "chains" in
each hashtable bucket."""
self.index = index
self.next = next
def __init__(self, n_buckets=1000):
# the following two variables should be used to implement the "two-tiered"
# ordered hashtable described in class -- don't rename them!
self.indices = [None] * n_buckets
self.entries = []
self.count = 0
def __getitem__(self, key):
??????
def __setitem__(self, key, val):
????
def __delitem__(self, key)
???
Explanation / Answer
class OrderedHashtable: def __init__(self, index, next=None): """This class is used to create nodes in the singly linked "chains" in each hashtable bucket.""" self.index = index self.next = next def __init__(self, n_buckets=1000): # the following two variables should be used to implement the "two-tiered" # ordered hashtable described in class -- don't rename them! self.indices = [None] * n_buckets self.entries = [] self.count = 0 def __getitem__(self, key): if(self.entries[key]!=-1): return self.entries[key] def __setitem__(self, key, val): self.entries[key] = val def __delitem__(self, key): self.entries[key] = -1
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.