nginx hash结构

nginx hash结构

hash_init中不明白的地方:
start = nelts / (bucket_size / (2 * sizeof(void *)));
start = start ? start : 1;

每个元素最少需要 NGX_HASH_ELT_SIZE(&names[n]) > (2 * sizeof(void *))
空间(经过对齐之后确实大于),因此bucket_size大小的桶至多能放bucket_size / (2 * sizeof(void *)))
个元素,因此nelts个元素就最少需要start个桶了.

对于正则匹配的ngx_hash_wildcard_t 结构:

<.com, “220.181.111.147”>,<.baidu.com, “220.181.111.147”>,<.baidu.com.cn, “220.181.111.147”>,<.google.com,”58.63.236.35”>
  (1)通过函数ngx_hash_add_key将上面的键值对加入到ngx_hash_keys_arrays_t结构中的dns_wc_head数组中,该数组的值如下图所示:
  {key = (“com.” , 4 ), key_hash = 0 , value = “220.181.111.147”}
  {key = (“cn.com.baidu.” , 13), key_hash = 0 , value = “220.181.111.147”}
  {key = (“com.baidu.” , 10), key_hash = 0 , value = “220.181.111.147”}
  {key = (“com.google.” , 11), key_hash = 0 , value = “58.63.236.35”}
(2)将上面的dns_wc_head数组传递给ngx_hash_wildcard_init,生成的hash如下图所示:
nginx hash结构

相关文章:

  • 2022-02-18
  • 2021-11-03
  • 2022-03-03
  • 2021-10-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-13
  • 2022-02-01
  • 2021-11-26
  • 2022-12-23
  • 2022-12-23
  • 2021-06-26
  • 2021-09-09
相关资源
相似解决方案