Ejemplo n.º 1
0
    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()
Ejemplo n.º 2
0
    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()
Ejemplo n.º 3
0
 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()
Ejemplo n.º 4
0
 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()
Ejemplo n.º 5
0
    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)
Ejemplo n.º 6
0
    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()
Ejemplo n.º 7
0
 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()
Ejemplo n.º 8
0
 def __getitem__(self, key):
     index = key % self.tablesize
     if self.hashtable[index]:
         return self.hashtable[index].find(key)
     else:
         raise Exeption.NotFoundException()
Ejemplo n.º 9
0
 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)