惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
Apple Machine Learning Research
Apple Machine Learning Research
小众软件
小众软件
Recent Announcements
Recent Announcements
阮一峰的网络日志
阮一峰的网络日志
IT之家
IT之家
A
About on SuperTechFans
量子位
Engineering at Meta
Engineering at Meta
B
Blog
The Cloudflare Blog
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
Y
Y Combinator Blog
J
Java Code Geeks
D
DataBreaches.Net
aimingoo的专栏
aimingoo的专栏
T
Tailwind CSS Blog
H
Help Net Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
V2EX
Stack Overflow Blog
Stack Overflow Blog
C
Check Point Blog
酷 壳 – CoolShell
酷 壳 – CoolShell

博客园 - 天下大事 必作于细

boost::wave 简单就是美 My first AutoCAD journey UI testing my video card Something wrong in the msdn 租房成功 稀里糊涂去办了护照 告别紫丁香 真的很疼 继续yy 崩溃了 随感 重读《谁动了我的奶酪?》 《C++模板元编程》精彩书评(From china-pub) 五一归来后的学习计划 终于拿到auto的offer了 二面 关于SGI STL源码中hashtable的一点疑问
续:关于SGI STL源码中hashtable的一点疑问
天下大事 必作于细 · 2007-04-04 · via 博客园 - 天下大事 必作于细
   

经过pangwa大哥的指点,对于这个问题终于有点明白了。
   
   其实__h = __h * 5 + *(__s++)只是一种实现string到long转换的方式而已。

   在php中,就是用了一下方法转换string:

static unsigned long hashpjw(char *arKey, unsigned int nKeyLength)

{

   unsigned long h = 0, g;

   char *arEnd=arKey+nKeyLength;


   while (arKey < arEnd) {

      h = (h << 4) + *arKey++;

      if ((g = (h & 0xF0000000))) {

         h = h ^ (g >> 24);

         h = h ^ g;

      }

   }

   return h;

}


   大家可以看到,在php中,使用的是一个移位算法来将一个字符串转为long型。

   参考文章:http://blog.iyi.cn/tech/2005/11/post_2.html

   感谢:pangwa大哥