def update(self, key, data): index = key % self.tablesize if self.hashtable[index] is not None: if self.hashtable[index].contains(key) is False: raise Exeption.NotFoundException() self.hashtable[index].update(key, data) else: raise Exeption.NotFoundException()
def find(self, key): index = key % self.tablesize if self.hashtable[index] is not None: if self.hashtable[index].contains(key) is False: raise Exeption.NotFoundException() return self.hashtable[index].find(key) else: raise Exeption.NotFoundException()
def find(self,key): temp=self.head while temp is not None: if temp.key is key: return temp.data temp=temp.next raise Exeption.NotFoundException()
def update(self,key,data): temp=self.head while temp is not None: if temp.key is key: temp.data=data return temp=temp.next raise Exeption.NotFoundException()
def insert(self,key,data): if(self.head==None): self.head=Node.Node(key,data) else: temp=self.head while temp.next is not None: if temp.key is key: raise Exeption.ItemExistsException() temp=temp.next temp.next=Node.Node(key,data)
def insert(self, key, data): index = key % self.tablesize if self.hashtable[index] is None: self.hashtable[index] = Bucket.Bucket() if (self.hashtable[index].contains(key)): raise Exeption.ItemExistsException() self.hashtable[index].insert(key, data) if (len(self) > self.tablesize * 1.20): self.rebuild()
def remove(self,key): #this is an special case which is removing head of the list if self.head.key is key: self.head=self.head.next return temp=self.head pre=None while temp is not None: if temp.key is key: pre.next=temp.next return pre=temp temp=temp.next Exeption.NotFoundException()
def __getitem__(self, key): index = key % self.tablesize if self.hashtable[index]: return self.hashtable[index].find(key) else: raise Exeption.NotFoundException()
def remove(self, key): index = key % self.tablesize if self.hashtable[index] is not None: if self.hashtable[index].contains(key) is False: raise Exeption.NotFoundException() self.hashtable[index].remove(key)