Hashtable implementation example in PHP share _php instance

Source: Internet
Author: User
Tags php foreach

The PHP kernel has a certain understanding of people should know that the essence of PHP is hashtable,hashtable in the implementation of PHP everywhere. Including the PHP array, what global variables, the scope of local variables, and so on, PHP Hashtable is divided into four parts:

hash function: A time33 hash function that converts the key of a string into a number
A C-array: Used to store buckets (buckets)
Two doubly linked lists: The first two-way list is an array of each element (bucket bucket) is a two-way linked list, this is done in order to resolve the hash conflict; the second doubly linked list is an array that joins each bucket (bucket), which is connected to the first doubly linked list of linked lists, This is done to traverse the entire hash table used, bird brother has a blog is talking about PHP foreach, here This design is for foreach with ==> "In-depth understanding of PHP array (traversal order)"
I am not here to say Hashtable of the struct and bucket struct, because the following recommended links are almost all said, I do not think I can describe and say better than they, everyone's level is not the same, I am now the level of technology to describe, So I just keep a record of what I've sorted.

The following is a hash implementation in PHP two files: zend_hash.c zend_hash.h. These two files implement a stack of APIs, but also a stack of APIs, the following is the prototype of the API implemented

Copy Code code as follows:

ZEND_API ULONG Zend_hash_func (const char *arkey, UINT nkeylength)
ZEND_API ULONG Zend_get_hash_value (const char *arkey, UINT nkeylength)
Zend_api int _zend_hash_init (HashTable *ht, uint nsize, hash_func_t phashfunction, dtor_func_t pdestructor, Zend_bool per Sistent zend_file_line_dc)
Zend_api void Zend_hash_set_apply_protection (HashTable *ht, Zend_bool bapplyprotection)
Zend_api int _zend_hash_add_or_update (HashTable *ht, const char *arkey, uint nkeylength, void *pdata, uint ndatasize, void **pdest, int flag zend_file_line_dc)
Zend_api int _zend_hash_quick_add_or_update (HashTable *ht, const char *arkey, UINT nkeylength, ulong h, void *pdata, uint Ndatasize, void **pdest, int flag zend_file_line_dc)
Zend_api int _zend_hash_index_update_or_next_insert (HashTable *ht, ulong h, void *pdata, uint ndatasize, void **pdest, int Flag ZEND_FILE_LINE_DC)
Zend_api int Zend_hash_rehash (HashTable *ht)
static int zend_hash_do_resize (HashTable *ht)
Zend_api int Zend_hash_del_key_or_index (HashTable *ht, const char *arkey, UINT nkeylength, ulong h, int flag)
Zend_api void Zend_hash_destroy (HashTable *ht)
Zend_api void Zend_hash_clean (HashTable *ht)
Static Bucket *zend_hash_apply_deleter (HashTable *ht, Bucket *p)
Zend_api void Zend_hash_graceful_destroy (HashTable *ht)
Zend_api void Zend_hash_graceful_reverse_destroy (HashTable *ht)
Zend_api void Zend_hash_apply (HashTable *ht, apply_func_t apply_func)
Zend_api void Zend_hash_apply_with_argument (HashTable *ht, apply_func_arg_t apply_func, void *argument TSRMLS_DC)
Zend_api void Zend_hash_apply_with_arguments (HashTable *ht tsrmls_dc, apply_func_args_t apply_func, int num_args, ...)
Zend_api void Zend_hash_reverse_apply (HashTable *ht, apply_func_t apply_func)
Zend_api void Zend_hash_copy (HashTable *target, HashTable *source, copy_ctor_func_t pcopyconstructor, void *tmp, uint siz E
Zend_api void _zend_hash_merge (HashTable *target, HashTable *source, copy_ctor_func_t pcopyconstructor, void *tmp, uint s ize, int overwrite zend_file_line_dc)
Static Zend_bool Zend_hash_replace_checker_wrapper (HashTable *target, void *source_data, Bucket *p, void *pparam, Merge_ checker_func_t Merge_checker_func)
Zend_api void Zend_hash_merge_ex (HashTable *target, HashTable *source, copy_ctor_func_t pcopyconstructor, uint size, merge_checker_func_t pmergesource, void *pparam)
ZEND_API int Zend_hash_find (const HashTable *HT, const char *arkey, uint nkeylength, void **pdata)
ZEND_API int Zend_hash_quick_find (const HashTable *HT, const char *arkey, UINT nkeylength, ulong h, void **pdata)
ZEND_API int zend_hash_exists (const HashTable *HT, const char *arkey, UINT nkeylength)
ZEND_API int zend_hash_quick_exists (const HashTable *HT, const char *arkey, UINT nkeylength, ulong h)
ZEND_API int Zend_hash_index_find (const HashTable *HT, ulong h, void **pdata)
ZEND_API int zend_hash_index_exists (const HashTable *HT, ULONG h)
ZEND_API int zend_hash_num_elements (const HashTable *HT)
ZEND_API int Zend_hash_get_pointer (const HashTable *HT, Hashpointer *ptr)
Zend_api int Zend_hash_set_pointer (HashTable *ht, const hashpointer *ptr)
Zend_api void Zend_hash_internal_pointer_reset_ex (HashTable *ht, hashposition *pos)
Zend_api void Zend_hash_internal_pointer_end_ex (HashTable *ht, hashposition *pos)
Zend_api int zend_hash_move_forward_ex (HashTable *ht, hashposition *pos)
Zend_api int zend_hash_move_backwards_ex (HashTable *ht, hashposition *pos)
ZEND_API int zend_hash_get_current_key_ex (const HashTable *ht, char **str_index, uint *str_length, ulong *num_index, ZEND _bool Duplicate, hashposition *pos)
Zend_api int zend_hash_get_current_key_type_ex (HashTable *ht, hashposition *pos)
Zend_api int zend_hash_get_current_data_ex (HashTable *ht, void **pdata, Hashposition *pos)
Zend_api int zend_hash_update_current_key_ex (HashTable *ht, int key_type, const char *str_index, UINT str_length, ulong nu M_index, int mode, hashposition *pos)
Zend_api int Zend_hash_sort (HashTable *ht, sort_func_t sort_func, compare_func_t compar, int renumber tsrmls_dc)
Zend_api int Zend_hash_compare (HashTable *ht1, HashTable *ht2, compare_func_t compar, Zend_bool ordered TSRMLS_DC)
ZEND_API int Zend_hash_minmax (const HashTable *HT, compare_func_t compar, int flag, void **pdata tsrmls_dc)
ZEND_API ULONG zend_hash_next_free_element (const HashTable *HT)
void Zend_hash_display_plisttail (const HashTable *HT)
void Zend_hash_display (const HashTable *HT)

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.