Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

哈希表的二次探测函数有bug,会出现无限循环 #34

Open
@loveleicheng

Description

@loveleicheng

大佬,你这里哈希表的二次探测函数,会出现无限循环的情况。

def_find_slot_for_insert(self,key):index=self._hash(key)_len=len(self._table)whilenotself._slot_can_insert(index):# 直到找到一个可以用的槽index= (index*5+1)%_lenreturnindexdef_slot_can_insert(self,index):return (self._table[index]isHashTable.EMPTYorself._table[index]isHashTable.UNUSED)

如上,如果index为5,此时5的位置上如果存在数据了,则需要继续找。假设此时_len为7,index为5, 则:(5 * 5 + 1)% 7 结果最终还是5,循环就无法跳出。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp