PegasusWang / python_data_structures_and_algorithms

Python 中文数据结构和算法教程

Home Page:http://pegasuswang.github.io/python_data_structures_and_algorithms/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HashTable里的_find_key() 是有bug,还是我理解有问题

BenYuLong opened this issue · comments

    def _find_key(self, key):
        index = self._hash(key)
        _len = len(self._table)
        while self._table[index] is not HashTable.UNUSED:
            if self._table[index] is HashTable.EMPTY:
                index = (index*5 + 1) % _len
                continue
            elif self._table[index].key == key:
                return index
            else:
                index = (index*5 + 1) % _len
        return None

如果此时 len=8,table里有5个有效值3个EMPTY没有UNUSED,此时find的key不是5个有效值之一,那不是就永远不会退出while了吗?

感谢指出,这里确实有 bug,已经更新代码。如果还有其他问题,可以单开一个 issue。54b8b2f