forked from TheAlgorithms/Python
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash_table_with_linked_list.py
More file actions
Latest commit
27 lines (21 loc) · 846 Bytes
/
Copy pathhash_table_with_linked_list.py
File metadata and controls
27 lines (21 loc) · 846 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
fromcollectionsimportdeque
from .hash_tableimportHashTable
classHashTableWithLinkedList(HashTable):
def__init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def_set_value(self, key, data):
self.values[key] =deque([]) ifself.values[key] isNoneelseself.values[key]
self.values[key].appendleft(data)
self._keys[key] =self.values[key]
defbalanced_factor(self):
return (
sum(self.charge_factor-len(slot) forslotinself.values)
/self.size_table
*self.charge_factor
)
def_collision_resolution(self, key, data=None):
ifnot (
len(self.values[key]) ==self.charge_factorandself.values.count(None) ==0
):
returnkey
returnsuper()._collision_resolution(key, data)