哪个 PHP 函数使用了这种哈希算法?

发布于 2024-10-03 11:24:50 字数 1510 浏览 9 评论 0原文

   1. static inline ulong zend_inline_hash_func(char *arKey, uint nKeyLength)
   2. {
   3.     register ulong hash = 5381;
   4.  
   5.     /* variant with the hash unrolled eight times */
   6.     for (; nKeyLength >= 8; nKeyLength -= 8) {
   7.         hash = ((hash << 5) + hash) + *arKey++;
   8.         hash = ((hash << 5) + hash) + *arKey++;
   9.         hash = ((hash << 5) + hash) + *arKey++;
  10.         hash = ((hash << 5) + hash) + *arKey++;
  11.         hash = ((hash << 5) + hash) + *arKey++;
  12.         hash = ((hash << 5) + hash) + *arKey++;
  13.         hash = ((hash << 5) + hash) + *arKey++;
  14.         hash = ((hash << 5) + hash) + *arKey++;
  15.     }
  16.     switch (nKeyLength) {
  17.         case 7: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
  18.         case 6: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
  19.         case 5: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
  20.         case 4: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
  21.         case 3: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
  22.         case 2: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
  23.         case 1: hash = ((hash << 5) + hash) + *arKey++; break;
  24.         case 0: break;
  25. EMPTY_SWITCH_DEFAULT_CASE()
  26.     }
  27.     return hash;
  28. }
   1. static inline ulong zend_inline_hash_func(char *arKey, uint nKeyLength)
   2. {
   3.     register ulong hash = 5381;
   4.  
   5.     /* variant with the hash unrolled eight times */
   6.     for (; nKeyLength >= 8; nKeyLength -= 8) {
   7.         hash = ((hash << 5) + hash) + *arKey++;
   8.         hash = ((hash << 5) + hash) + *arKey++;
   9.         hash = ((hash << 5) + hash) + *arKey++;
  10.         hash = ((hash << 5) + hash) + *arKey++;
  11.         hash = ((hash << 5) + hash) + *arKey++;
  12.         hash = ((hash << 5) + hash) + *arKey++;
  13.         hash = ((hash << 5) + hash) + *arKey++;
  14.         hash = ((hash << 5) + hash) + *arKey++;
  15.     }
  16.     switch (nKeyLength) {
  17.         case 7: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
  18.         case 6: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
  19.         case 5: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
  20.         case 4: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
  21.         case 3: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
  22.         case 2: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
  23.         case 1: hash = ((hash << 5) + hash) + *arKey++; break;
  24.         case 0: break;
  25. EMPTY_SWITCH_DEFAULT_CASE()
  26.     }
  27.     return hash;
  28. }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

望笑 2024-10-10 11:24:50

所有哈希表都使用该哈希算法;例如,PHP 中的哈希表可用于实现数组和符号表等。

标头中指出的算法是 DJBX33A (Daniel J伯恩斯坦,《泰晤士报》第 33 期,附有补充)。

All the hash tables use that hashing algorithm; hash tables in PHP are used, for instance, to implement arrays and symbol tables, among many other things.

The algorithm, as pointed in the header is DJBX33A (Daniel J. Bernstein, Times 33 with Addition).

迷荒 2024-10-10 11:24:50

您可以使用此链接查看该函数的使用位置:
http: //lxr.php.net/search?q=+zend_inline_hash_func&defs=&refs=&path=&hist=&project=PHP_5_4

看起来有 3 个 php 扩展(包括标准扩展),其中使用此功能。

You can use this link to see where this function is used:
http://lxr.php.net/search?q=+zend_inline_hash_func&defs=&refs=&path=&hist=&project=PHP_5_4

looks like there are 3 php extensions (including standard) where this function is used.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文