国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PHP > 正文

php hash算法實現(xiàn)數(shù)組的方法

2024-05-04 21:48:48
字體:
供稿:網(wǎng)友

PHP中使用最多的非Array莫屬了,那Array是如何實現(xiàn)的?在PHP內(nèi)部Array通過一個hashtable來實現(xiàn),其中使用鏈接法解決hash沖突的問題,這樣最壞情況下,查找Array元素的復(fù)雜度為O(N),最好則為1.

  1. static inline ulong zend_inline_hash_func(const char *arKey, uint nKeyLength)  
  2. {  
  3. register ulong hash = 5381; //此處初始值的設(shè)置有什么玄機(jī)么?  
  4. /* variant with the hash unrolled eight times */  
  5. for (; nKeyLength >= 8; nKeyLength -= 8) { //這種step=8的方式是為何?  
  6. hash = ((hash << 5) + hash) + *arKey++;  
  7. hash = ((hash << 5) + hash) + *arKey++;  
  8. hash = ((hash << 5) + hash) + *arKey++;  
  9. hash = ((hash << 5) + hash) + *arKey++; //比直接*33要快  
  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. }  
  15. switch (nKeyLength) {  
  16. case 7: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */ //此處是將剩余的字符hash //開源代碼Vevb.com 
  17. case 6: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */  
  18. case 5: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */  
  19. case 4: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */  
  20. case 3: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */  
  21. case 2: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */  
  22. case 1: hash = ((hash << 5) + hash) + *arKey++; break;  
  23. case 0: break;  
  24. EMPTY_SWITCH_DEFAULT_CASE()  
  25. }  
  26. return hash;//返回hash值  
  27. }

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 孙吴县| 嵊州市| 高淳县| 舒城县| 东莞市| 辽中县| 峨山| 揭东县| 荔波县| 柞水县| 闻喜县| 高邑县| 来凤县| 宣城市| 惠安县| 高碑店市| 隆林| 黔西县| 政和县| 鄄城县| 沧源| 莆田市| 来宾市| 霍林郭勒市| 阿图什市| 安阳县| 来凤县| 甘德县| 刚察县| 敖汉旗| 大兴区| 宝丰县| 武山县| 乌拉特后旗| 高碑店市| 海林市| 徐水县| 墨竹工卡县| 古丈县| 老河口市| 文成县|