hash_map.py
def resize_table(self, new_capacity: int) -> None:
        """
        Change the capacity of the internal hash table and re-hash
        all key/value pairs.
        If `new_capacity` < 1 the method does nothing.
        :param new_capacity: an int
        :return: None
        """
        if new_capacity > 0:
            # Create new HashMap and buckets
            temp = HashMap(new_capacity, self.hash_function)
            for i in range(new_capacity):
                temp.buckets.append(LinkedList())
            # Re-hash contents of original map into temp_buckets
            for j in range(self.capacity):
                if self.buckets[j].length() > 0:
                    for node in self.buckets[j]:
                        temp.put(node.key, node.value)
            while self.capacity > 0:  # Clear old data from self
                self.buckets.pop()
                self.capacity -= 1
            for i in range(temp.capacity):  # Add re-hashed data to self
                self.buckets.append(temp.buckets[i])
                self.capacity += 1

        Change the capacity of the internal hash table and re-hash
        all key/value pairs.
        If `new_capacity` < 1 the method does nothing.
        :param new_capacity: an int
        :return: None
        
Change the capacity of the internal hash table and re-hash
all key/value pairs.
If `new_capacity` < 1 the method does nothing.
Change the capacity of the internal hash table and re - hash all key / value pairs . If ` new_capacity ` < 1 the method does nothing .
def resize_table(self, new_capacity: int) -> None:
        if new_capacity > 0:
            temp = HashMap(new_capacity, self.hash_function)
            for i in range(new_capacity):
                temp.buckets.append(LinkedList())
            for j in range(self.capacity):
                if self.buckets[j].length() > 0:
                    for node in self.buckets[j]:
                        temp.put(node.key, node.value)
            while self.capacity > 0:  
                self.buckets.pop()
                self.capacity -= 1
            for i in range(temp.capacity):  
                self.buckets.append(temp.buckets[i])
                self.capacity += 1
def resize_table ( self , new_capacity : int ) -> None : if new_capacity > 0 : temp = HashMap ( new_capacity , self . hash_function ) for i in range ( new_capacity ) : temp . buckets . append ( LinkedList ( ) ) for j in range ( self . capacity ) : if self . buckets [ j ] . length ( ) > 0 : for node in self . buckets [ j ] : temp . put ( node . key , node . value ) while self . capacity > 0 : self . buckets . pop ( ) self . capacity -= 1 for i in range ( temp . capacity ) : self . buckets . append ( temp . buckets [ i ] ) self . capacity += 1
Change the capacity of the internal hash table and re-hash
all key/value pairs.
Change the capacity of the internal hash table and re - hash all key / value pairs .
"""
        Change the capacity of the internal hash table and re-hash
        all key/value pairs.
        If `new_capacity` < 1 the method does nothing.
        :param new_capacity: an int
        :return: None
        """ # Create new HashMap and buckets # Re-hash contents of original map into temp_buckets # Clear old data from self # Add re-hashed data to self
None
self
new_capacity
int
None