PHP Hashtable implementation sample sharing _php Tutorial

Source: Internet
Author: User
Someone with a certain understanding of the PHP kernel should know that the essence of PHP is that hashtable,hashtable is ubiquitous in PHP implementations. Including the PHP array, what global variables, the scope of local variables, and so on, PHP hashtable apart is four parts:

Hash function: Use the TIME33 hash function to convert the key of a string into a number
A C array: used to store buckets (buckets).
Two two-way linked list: The first doubly linked list is an array of each element (bucket bucket) is a doubly linked list, which is done in order to resolve the hash conflict; the second doubly linked list is an array that connects each bucket (bucket), where the first doubly linked list is connected, This is to traverse the entire hash table with, bird Brother has a blog is to speak PHP foreach, here This design is to foreach with the ==> "in-depth understanding of PHP array (traversal order)"
I'm not talking about Hashtable's struct and bucket's struct anymore, because the following referral links are almost all said, I don't think I can describe and say better than them, each person's level is not the same, I am the current level of technology to describe, So I'll just record some of the things I've sorted out.

The following is a hash implementation of 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

Copy CodeThe code is 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 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)
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)

http://www.bkjia.com/PHPjc/735244.html www.bkjia.com true http://www.bkjia.com/PHPjc/735244.html techarticle someone with a certain understanding of the PHP kernel should know that the essence of PHP is that hashtable,hashtable is ubiquitous in PHP implementations. Including the PHP array, what global variables, the role of local variables ...

  • 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.