关于php中hashtable实现示例
来源:才华咖 本文已影响5.65K人
来源:才华咖 本文已影响5.65K人
对php内核有一定了解的人应该都知道php的精髓就是HashTable,HashTable在php的实现中无处不在。包括php的数组、什么全局变量、局部变量的作用域等等,php的hashtable拆开来说就是四部分,跟随小编与瞧一瞧!
hash函数:用的是time33的散列函数,将一个字符串的key转换成一个数字
一个C数组:用来储存桶(buckets)的
两个双向的链表:第一个双向链表是数组的每个元素(桶bucket)是一个双向链表,这样做是为了解决hash冲突;第二个双向链表是数组将每一个桶(bucket)连接起来,这里要连接的也就是第一个双向链表的'链表头,这样做是为了遍历整个hash表用的,鸟哥有篇blog是讲php的foreach的,这里这样设计就是给foreach用的==>《深入理解PHP之数组(遍历顺序)》
我这里不再说hashtable的struct和bucket的struct了,因为下面的推荐链接几乎都讲了,我不觉得我能描述和说的比他们好,每个人的水平不一样,我就以我现在的技术水平来描述,所以我就只把我整理的一些东西记录一下
下面是php中hash实现的两个文件:zend_hash.c zend_hash.h。这两个文件里面实现了一堆的api,也引申出了一堆的api,下面是实现出来的api的原型
复制代码 代码如下:
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 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 size)
ZEND_API void _zend_hash_merge(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 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 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 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) </p
java环境变量path和classpath的配置过程
高中英语作文范文How to Help the Disable
The relationship between theory and practice大学英语作文
To be really happy and really safe优秀英语作文
Champagne Bubbles Key to Tas英文阅读
关于apache mysql php 源码编译使用方法
关于JAVA实现httpClient的实例
C语言的HashTable简单实现
WEALTH AND HAPPINESS高中英语作文
英语美文欣赏:Happiness and Wealth
WinXP如何安装Apache+MySQL+PHP环境
关于Adobe为iPad版Photoshop Touch加入压敏触控笔支持
Adobe Photoshop Lightroom快速修图十大技巧
The truth about money and happiness高中英语作文
PPT职称考试“Shockwave Flash Object”控件法
php错误提示failed to open stream
Jolie drops battle over perfume named Shilohy英语作文
英语美文:Bush, watch out for the pretzels
关于现实的名言
关于java实现http请求工具类示例
Hot spring Let Me Have A Rest为题目的作文
四年级下册《Weather Part B Lets talk》教案
优秀英语作文Shuld places be cash-free?
基于PHP的个人网站设计与实现论文
How to Enhance the Sense of Happiness英语四级作文
An Apple for the Teacher英语六级作文
The Amazing Beach Party大学英语作文
英语阅读:What seems to be the problem
Javascript实例教程如何使用HoTMetal
如何启用Apache的PHP-FPM多实例
深入PHP中的HashTable结构详解
The Bitter and Happiness of Study英语作文
How to Deal with Sub-health英语四级作文
关于现实表现
The Cause of Sub-health亚健康的起因英语作文
对Java中HashMap和TreeMap的区别的深入理解
最大的幸福 The Great Happiness英语作文
How to keep a good relationship with parents英语作文
英语作文:Why Has Tourism Become Popular
英语作文The Happy Spring Festiva