Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the underlying implementation principle of php array?

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces what is the underlying implementation principle of php array, which is very detailed and has a certain reference value. Friends who are interested must read it!

The underlying implementation principle of php array

1. The underlying implementation is through hash table (hash table) + two-way linked list (resolve hash conflicts)

Hashtable: calculate the hash value (Bucket- > h) of different keywords (key) through the mapping function and then directly index to the corresponding Bucket.

The hash table holds the pointer to the current loop, so foreach is faster than for

Bucket: holds the key and value of array elements, as well as the hash value h

2. How to ensure order

1. Add a mapping table between the hash function and the array of elements (Bucket) that is the same size as the array of storage elements.

two。 Used to store the subscript of the element in the actual storage array

3. Elements are inserted into the actual storage array in the order of the mapping table

4. The mapping table is only an idea in principle. In fact, there will be no actual mapping table, but when Bucket memory is allocated during initialization, the same amount of uint32_t-sized space is allocated, and then the arData is offset to the location of the array of storage elements.

3. Solve hash duplication (linked list method used by php):

1. Linked list method: when different keywords point to the same unit, use the linked list to save the keywords (traversing the linked list to match key)

two。 Open addressing: when the keyword points to a cell that already has data, continue to look for other units until you find the available unit (occupy the location of other units, more prone to hash conflicts, performance degradation)

4. Basic knowledge

Linked lists: queues, stacks, two-way linked lists,

Linked list: element + pointer to the next element

Two-way linked list: pointer to the previous element + element + pointer to the next element

These are all the contents of the article "what is the underlying implementation of the php array?" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report