php中hashtable实现示例分享_php实例_脚本之家

对php内核有一定精通的人应有都清楚php的精粹便是HashTable,HashTable在php的兑现中无处不在。满含php的数组、什么全局变量、局部变量的功用域等等,php的hashtable拆开的话就是四片段:

hash函数:用的是time33的散列函数,将两个字符串的key转变到二个数字一个C数组:用来储存桶的八个双向的链表:第二个双向链表是数组的每一个成分是贰个双向链表,那样做是为着消除hash冲突;第二个双向链表是数组将每三个桶连接起来,这里要一而再再而三的也正是第叁个双向链表的链表头,这样做是为着遍历整个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_rehashstatic int
zend_hash_do_resizeZEND_API int
zend_hash_del_key_or_index(HashTable *ht, const char *arKey, uint
nKeyLength, ulong h, int flag)ZEND_API void
zend_hash_destroyZEND_API void zend_hash_cleanstatic Bucket
*zend_hash_apply_deleter(HashTable *ht, Bucket *p)ZEND_API void
zend_hash_graceful_destroyZEND_API void
zend_hash_graceful_reverse_destroyZEND_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_elementsZEND_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_elementvoid zend_hash_display_pListTailvoid
zend_hash_display

相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图