Phphash algorithm array implementation method _ PHP Tutorial

Source: Internet
Author: User
The phphash algorithm implements arrays. The most commonly used non-Array in PHP does not belong to. how is Array implemented? In PHP, the Array is implemented through a hashtable, and the link method is used to solve the hash conflict problem. in this way, the most used non-Array in PHP is the worst case, how is Array implemented? In PHP, the internal Array is implemented through a hashtable, and the hash conflict is solved using the link method. in this case, the complexity of searching Array elements is O (N ), preferably 1.

The most commonly used non-Array in PHP does not belong to. how is Array implemented? In PHP, the internal Array is implemented through a hashtable, and the hash conflict is solved using the link method. in this case, the complexity of searching Array elements is O (N ), preferably 1.

Static inline ulong zend_inline_hash_func (const char * arKey, uint nKeyLength)
{
Register ulong hash = 5381; // is there any xuanjicang in the initial value settings?
/* Variant with the hash unrolled eight times */
For (; nKeyLength> = 8; nKeyLength-= 8) {// why is this step = 8?
Hash = (hash <5) + hash) + * arKey ++;
Hash = (hash <5) + hash) + * arKey ++;
Hash = (hash <5) + hash) + * arKey ++;
Hash = (hash <5) + hash) + * arKey ++; // faster than * 33
Hash = (hash <5) + hash) + * arKey ++;
Hash = (hash <5) + hash) + * arKey ++;
Hash = (hash <5) + hash) + * arKey ++;
Hash = (hash <5) + hash) + * arKey ++;
}
Switch (nKeyLength ){
Case 7: hash = (hash <5) + hash) + * arKey ++;/* fallthrough... * // the remaining characters are hashed here
Case 6: hash = (hash <5) + hash) + * arKey ++;/* fallthrough ...*/
Case 5: hash = (hash <5) + hash) + * arKey ++;/* fallthrough ...*/
Case 4: hash = (hash <5) + hash) + * arKey ++;/* fallthrough ...*/
Case 3: hash = (hash <5) + hash) + * arKey ++;/* fallthrough ...*/
Case 2: hash = (hash <5) + hash) + * arKey ++;/* fallthrough ...*/
Case 1: hash = (hash <5) + hash) + * arKey ++; break;
Case 0: break;
EMPTY_SWITCH_DEFAULT_CASE ()
}
Return hash; // return the hash value.
}

Why? In PHP, Array is implemented through a hashtable, and the link method is used to solve the hash conflict problem. this is the worst case...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.