@@ -75,16 +75,16 @@ def _find_slot(self, key, for_insert=False):
7575 if not for_insert : # 查找是否存在 key
7676 while self ._table [index ] is not HashTable .UNUSED :
7777 if self ._table [index ] is HashTable .EMPTY :
78- index = (index + hash_times * hash_times ) % _len # 一个简单的二次方探查
78+ index = (base_index + hash_times * hash_times ) % _len # 一个简单的二次方探查
7979 continue
8080 elif self ._table [index ].key == key :
8181 return index
82- index = (index + hash_times * hash_times ) % _len
82+ index = (base_index + hash_times * hash_times ) % _len
8383 hash_times += 1
8484 return None
8585 else :
8686 while not self ._slot_can_insert (index ): # 循环直到找到一个可以插入的槽
87- index = (index + hash_times * hash_times ) % _len
87+ index = (base_index + hash_times * hash_times ) % _len
8888 hash_times += 1
8989 return index
9090
@@ -194,9 +194,9 @@ def test_set_adt():
194194 sb .add (4 )
195195 sb .add (5 )
196196
197- sorted (list (sa & sb )) == [3 ]
198- sorted (list (sa - sb )) == [1 , 2 ]
199- sorted (list (sa | sb )) == [1 , 2 , 3 , 4 , 5 ]
197+ assert sorted (list (sa & sb )) == [3 ]
198+ assert sorted (list (sa - sb )) == [1 , 2 ]
199+ assert sorted (list (sa | sb )) == [1 , 2 , 3 , 4 , 5 ]
200200
201201
202202if __name__ == '__main__' :
0 commit comments