python字典的冲突处理

18 views
Skip to first unread message

yongcong wang

unread,
Dec 15, 2009, 6:37:42 AM12/15/09
to 梦幻之星
CPyton的实现,伪码如下:

/* Starting slot */
slot = hash;

/* Initial perturbation value */
perturb = hash;
while (<slot is full> && <item in slot doesn't equal the key>) {
slot = (5*slot) + 1 + perturb;
perturb >>= 5;
// 补充下:5*slot通过(slot<<2)+slot实现,当然最后还要slot&mask
}

右移5位是通过统计得出的结果,比4位或6位产生更少的冲突

备忘,引擎的hash table可以参考下

Reply all
Reply to author
Forward
0 new messages