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. }
2
A
答えて
4
すべてのハッシュテーブルは、そのハッシュアルゴリズムを使用します。たとえば、配列やシンボルテーブルを実装するために、PHPのハッシュテーブルが使用されています。 で指摘されているアルゴリズムは、DJBX33A(Daniel J. Bernstein、Times 33 with Addition)です。
1
あなたは、この機能が使用されている場所を確認するために、このリンクを使用することができます。この機能を使用する(標準を含む)3つのPHP拡張があるよう http://lxr.php.net/search?q=+zend_inline_hash_func&defs=&refs=&path=&hist=&project=PHP_5_4
が見えます。
これは、PHPユーザーのためのこのようなAPIなしで、PHP内部でのみ使用されていますか? – ajx
私もこれで答えようとしていましたが、確信が持てませんでした。あなたが確認したように見えます。+1 – BoltClock
@ajx私が知る限り、ユーザーランド用のAPIはありません。 – Artefacto