关于map源代码中evacuate的一个问题

35 views
Skip to first unread message

nopsky

unread,
Nov 7, 2013, 4:16:21 AM11/7/13
to golang...@googlegroups.com
在hashmap.c中302行:

newbit = (uintptr)1 << (h->B - 1);

这里为啥需要 h->B - 1,不能直接h->B进行扩容吗?

Tw

unread,
Nov 7, 2013, 6:31:27 AM11/7/13
to golang...@googlegroups.com, nopsky
于2013年11月7日 17:16:21,nopsky写到:
> 在hashmap.c中302行:
>
> newbit = (uintptr)1 << (h->B - 1);
>
> 这里为啥需要 h->B - 1,不能直接h->B进行扩容吗?
>
> --
> --
> 官网: http://golang-china.org/
> IRC: irc.freenode.net #golang-china
> @golangchina
> ---
> 您收到此邮件是因为您订阅了 Google 网上论坛的“Golang-China”论坛。
> 要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到 golang-
> china+un...@googlegroups.com
> 要在网络上查看此讨论,请访问 https://groups.google.com/d/msgid/golang-
> china/etPan.527b5a65.6b8b4567.65da%40nopsky.local。
> 要查看更多选项,请访问 https://groups.google.com/groups/opt_out

扩容并不在evacuate函数中,见hash_grow函数464行。
ps:
之前写过一个hashmap的源码分析:http://totorow.herokuapp.com/posts/Read_Go_-_Map
可以参考。

cnno...@gmail.com

unread,
Nov 8, 2013, 12:56:29 AM11/8/13
to golang...@googlegroups.com, nopsky
我是看着你的文章读的代码:), 不过hash_grow应该是对已有的hash进行扩容后进行操作了吧
当程序正在进行evacuate的时候,不知道newbit的计算方式为什么是(uintptr)1 << (h->B - 1);看不明白为啥要h->B -1.

在 2013年11月7日星期四UTC+8下午7时31分27秒,Tw写道:
Reply all
Reply to author
Forward
0 new messages