예제 #1
0
    def resize_array(self):
        """ Resizes table and rehashes data
        Args:
            None
        Returns:
            None
        Raises:
            None
        Precondition:
            Unchanged hash table
        Postcondition:
            Table is resized and rehashed
        """
        old_hash = self.array
        # reset stats
        self.table_size += 2
        self.array = build_array(self.table_size)
        self.count = 0
        self.collisions = 0
        self.avg_probe_length = 0
        self.load = 0

        # re-hash old key-value pairs
        for i in old_hash:
            if i is not None:
                self[i.key] = i.value
 def __init__(self, maxCapacity=20):
     """
     Keyword Arguments:
         maxCapacity {int} -- size of array, must not less than 20 (default: {20})
     """
     if maxCapacity < 20:
         maxCapacity = 20
     self.array = build_array(maxCapacity)
     self._count = 0
예제 #3
0
 def __init__(self):  # initialise base size to 20
     '''
     Initialises a list for us of chosen size
     :complexity: O(N)
     '''
     # assert maximum > 0, "Enter a valid number"
     self.array = build_array(20)
     self.count = 0
     self.max = 20
 def __init__(self):
     """
         This is a constructor for class ArrayList.
         :param: None.
         :return: None.
         :exception: NONE.
         :pre-condition: A array, a counter.
         :post-condition: An array-based list object with a size 30 will be created.
         :complexity: O(1)
         """
     self.array = build_array(50)
     self.count = 0
예제 #5
0
 def __init__(self, table_size):
     """
     Initialises the hash_table with an array storing any given data
     :param table_size: the size of the hash_table in which array
     :return: None
     :raise: ValueError when string is given
     """
     if not self.is_digit(table_size):
         raise ValueError("Please give a number for table size")
     self.size = table_size
     self.hash_table = build_array(table_size)
     self.count = 0
예제 #6
0
 def resize(self):
     '''
     Resizing a list if
     :return: self.max
     :complexity: best case O(1) worst case O(N)
     '''
     if self._is_full():
         temp = self.array
         self.max = self.max * 2
         self.array = build_array(self.max)
         # Now copy values in
         for i in range(self.count):
             self.array[i] = temp[i]
     elif 20 < self.count < int((1 / 8) * self.max):
         temp = self.array
         self.max = self.max // 2
         self.array = build_array(self.max)
         # Now copy values in
         for i in range(self.count):
             self.array[i] = temp[i]
     return self.max
예제 #7
0
 def rehash(self, oldhashtable):
     """
     A function that takes the old hash-table and then rehashs every value with a larger hash-table
     :complexity: Best case O(n) and worst case, n being the size of the list
     :precondition: A key existing in the table
     :postcondition: A boolean value of the result
     :param oldhashtable: the old hash-table to copy from
     :return: A new hashtable doubled in size
     """
     newsize = self.size * 2
     self.size = newsize
     self.hash_table = build_array(newsize)
     for item in oldhashtable:
         if item is not None:
             self[item[0]] = item[1]
예제 #8
0
 def __init__(self, table_size=31):
     """ Hash table constructor
     Args:
         table_size (int): maximum size of the table
     Returns:
         None
     Raises:
         No exceptions
     Precondition:
         table_size > 0
     Postcondition:
         Creates a hash table instance
     """
     self.array = build_array(table_size)
     self.table_size = table_size
     self.count = 0
예제 #9
0
 def __init__(self, size):
     """ Constructor for ArrayBasedList
     Args:
         size (int): maximum size of the list
     Returns:
         None
     Raises:
         No exceptions
     Precondition:
         size cannot be negative    
     Postcondition:
         len(self.array) <= size
     Complexity:
         O(1)
     """
     self.array = build_array(size)
     self.maxSize = size
예제 #10
0
 def __init__(self):
     """ Constructor for ArrayBasedList
     Args:
         None
     Returns:
         None
     Raises:
         No exceptions
     Precondition:
         initial size of array == 20
     Postcondition:
         max size of array doubles if full, halves if contents
             occupy less than 1/8 of the max size
     Complexity:
         O(1)
     """
     self.array = build_array(20)
     self.maxSize = 20
예제 #11
0
 def __init__(self, table_size=31):
     """ Hash table constructor
     Args:
         table_size (int): initial maximum capacity of table
     Returns:
         None
     Raises:
         No exceptions
     Precondition:
         table_size > 0
     Postcondition:
         Creates a dynamic hash table instance
     """
     self.array = build_array(table_size)
     self.table_size = table_size
     self.count = 0
     self.collisions = 0
     self.avg_probe_length = 0
     self.load = 0
예제 #12
0
 def __init__(self,table_size=31):
     """ Hash table constructor
     Args:
         table_size (int): maximum size of the table
     Returns:
         None
     Raises:
         No exceptions
     Precondition:
         table_size > 0
     Postcondition:
         Creates a hash table instance that tracks collisions
             and average probe length
     """
     self.array = build_array(table_size)
     self.table_size = table_size
     self.count = 0
     self.collisions = 0
     self.avg_probe_length = 0
     self.load = 0
예제 #13
0
 def decrease(self):
     """ Decreases the size of the array
     Args:
         None
     Returns:
         None
     Raises:
         No exceptions
     Precondition:
         maxSize >= 0
     Postcondition:
         maxSize will be halved
         array is a new array with size maxSize and its previous
             contents preserved
     Complexity:
         O(n)
     """
     self.maxSize //= 2
     tmp = self.array
     self.array = build_array(self.maxSize)
     for i in tmp:
         self.append(i)
예제 #14
0
 def __init__(self):
     self.count = 0
     self.array = build_array(100)
 def __init__(self,tableSize=31):
     self.array = build_array(tableSize)
     self.tableSize = tableSize
     self.count = 0
 def __init__(self, size):
     self.array = build_array(size)
     self.maxSize = size
     self.top = 0
 def __init__(self, size):
     self.array = build_array(size)
     self.maxSize = size
     self.rear = 0
     self.front = 0
 def __init__(self,size):
     self.array = build_array(size)
     self.maxSize = size
     self.currentLen = 0
예제 #19
0
 def __init__(self, max_capacity):
     assert max_capacity > 0, "Max capacity has to be positive"
     self.count = 0
     self.array = build_array(max_capacity)
예제 #20
0
def rehash():
    new = build_array(ts * 2)
    for i in range(self.tablesize):
        if self.array[i] is not None:
예제 #21
0
 def __init__(self,tableSize, probeLengthList = [], count = 0):
     self.array = build_array(tableSize)
     self.tableSize = tableSize
     self.probeLengthList = probeLengthList
     self.count = count
예제 #22
0
 def __init__(self, size):
     self.array = build_array(size)
     self.count = 0
     self.top = -1
예제 #23
0
 def __init__(self, max_capacity):
     assert max_capacity > 0, 'eh?'
     self.array = build_array(max_capacity)
     self.count = 0
     self.top = -1