Nginx源代码分析--基本数据结构--hash
来源:互联网 发布:c数据分析师就业单位 编辑:程序博客网 时间:2024/05/29 12:28
这次我们来看一下查找函数
void *
ngx_hash_find(ngx_hash_t *hash, ngx_uint_t key, u_char *name, size_t len)
{
ngx_uint_t i;
ngx_hash_elt_t *elt;
#if 0
ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, "hf:/"%*s/"", len, name);
#endif
//hash->size的值是当前桶的个数。
//key%hash->size是该key会存储在哪个桶中。
//elt就是指向该桶的键值对的指针
elt = hash->buckets[key % hash->size];
if (elt == NULL) {
return NULL;
}
//如果elt->value==NULL,则表明已经达到该桶的k-v对的最后,说明查找不成功
while (elt->value) {
//先比较value的长度是否一致
if (len != (size_t) elt->len) {
goto next;
}
//如果长度一致,则比较每个字符是否一致
for (i = 0; i < len; i++) {
if (name[i] != elt->name[i]) {
goto next;
}
}
//如果查找到,返回值的指针
return elt->value;
next:
//知道当前的k-v的长度,和当前k-v对元素的指针,通过指针加运算,使得elt向后移动。
elt = (ngx_hash_elt_t *) ngx_align_ptr(&elt->name[0] + elt->len,
sizeof(void *));
continue;
}
return NULL;
}
- Nginx源代码分析--基本数据结构--hash
- Nginx源代码分析--基本数据结构--hash
- Nginx源代码分析--基本数据结构--hash
- Nginx源代码分析--基本数据结构--hash
- Nginx源代码分析--基本数据结构--hash
- Nginx源代码分析--基本数据结构--hash
- Nginx源代码分析--基本数据结构--hash
- nginx 基本hash的初始化 源码分析
- Nginx源码分析之基本数据结构
- 数据结构基本操作源代码
- nginx源代码分析
- nginx源代码分析
- nginx源代码分析
- Nginx 基本数据结构
- Nginx基本数据结构
- 【nginx】基本数据结构
- [nginx源码分析]server_name hash
- Nginx源码分析 - 基础数据结构篇 - hash表结构 ngx_hash.c
- ubuntu中配置任意应用的快捷键
- 活动图和流程图的区别
- 读取xml数据
- ActiveX调用 js脚本方法
- ln 命令 硬链接
- Nginx源代码分析--基本数据结构--hash
- 佛与魔
- 脚本执行期间在 IBM Rational Functional Tester 中获取并筛选日志
- 最令PHP初学者头痛的十四个问题
- Ext中FormPanel面板及Form控件横排测试(CSS)
- PHP - 序列化和反序列化
- PHPer的水平分段
- HashTable 使用例子
- 堆区(heap)和 栈区(stack)