to the PHP kernel has a certain understanding of people should know that the essence of PHP is Hashtable, this article mainly introduces the Hashtable implementation of PHP examples, the need for friends can refer to the following
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 four parts: hash function: With the hash function of the time33, the key to a string into a number of a C array: used to store buckets ( Buckets two bi-directional linked list: The first bidirectional linked list is an array of each element (bucket bucket) is a two-way linked list, which is done to resolve the hash conflict; the second doubly linked list is an array that connects each bucket (bucket), Here to connect is the first two-way linked list of linked list, this is done to traverse the entire hash table used, bird brother has a blog is about PHP foreach, here This design is for foreach with the ==> "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'm doing. The following is a hash implementation in PHP two files: zend_hash.c zend_hash.h. These two files implement a bunch of APIs, but also a bunch of APIs, the following is the implementation of the API prototype 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 persistent, 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 fl AG zend_file_line_dc) Zend_api int _zend_hash_quick_add_or_update (HashTable *ht, const char *arkey, uint nkeylength, Ulon G h, void *pdata, uint ndatasize, void **pdest, int flag zend_file_line_dc) Zend_api int _zend_hash_index_update_or_next_i Nsert (HashTable *ht, ulong h, void *pdata, uint ndatasize, void **pdest, int flag zend_file_line_dc) Zend_api int Zend_has H_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 Zen D_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 tsrmls_dc) 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) tsrmls_dc void Zend_api ( HashTable *target, HashTable *source, copy_ctor_func_t pcopyconstructor, void *tmp, uint size) Zend_api void _zend_hash_me Rge (HashTable *target, HashTable *source, copy_ctor_func_t pcopyconstructor, void *tmp, uint size, 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 in T Zend_hash_find (const HASHTAble *ht, const char *arkey, uint nkeylength, void **pdata) ZEND_API int zend_hash_quick_find (const HashTable *HT, const C Har *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) ZEN D_API int Zend_hash_index_find (const HashTable *HT, ulong h, void **pdata) ZEND_API int zend_hash_index_exists (const HASHT Able *ht, ULong h) ZEND_API int zend_hash_num_elements (const HashTable *ht) Zend_api int Zend_hash_get_pointer (cons T 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 in T 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 *p OS) Zend_api int zend_hash_update_current_key_ex (HashTable *ht, int key_type, const char *str_index, uint str_length, Ulon g Num_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 compa R, 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)