Пример #1
0
 def remove_index(self, index):
     next_index = self.search_fit_and_return_index(index)
     if next_index is None:
         self.container[index] = KeyValue(None, None)
     else:
         self.container[index] = self.container[next_index]
         self.remove_index(next_index)
Пример #2
0
 def add_capacity(self):
     container_copy = self.container.copy()
     self.counter = 0
     self.s *= 2
     self.container = [KeyValue(None, None) for i in range(self.s)]
     for item in container_copy:
         if item.key is not None:
             self.set(item.key, item.value)
Пример #3
0
 def set(self, key, value):
     index = self.hash(key)
     while True:
         if self.container[index].key is None:
             self.container[index] = KeyValue(key, value)
             self.counter += 1
             if self.counter * 2 > self.s:
                 self.add_capacity()
             return
         if self.container[index].key == key:
             self.container[index].value = value
             return
         index = self.increase(index)
Пример #4
0
 def __init__(self, s):
     self.s = s
     self.container = [KeyValue(None, None) for i in range(self.s)]
     self.counter = 0