小编nev*_*eft的帖子

为什么这个函数是一个不好的哈希函数?

我想知道为什么下面的代码片段是一个糟糕的哈希函数。

def computeHash(self, s):
    h = 0
    for ch in s:
    h = h + ord(ch) # ord gives the ASCII value of character ch
    return h % HASH_TABLE_SIZE
Run Code Online (Sandbox Code Playgroud)

如果我大幅增加哈希表的大小,这是否可以弥补哈希函数的不足?

python hash data-structures

2
推荐指数
1
解决办法
710
查看次数

标签 统计

data-structures ×1

hash ×1

python ×1