Igor Sysoev | 02f742b | 2005-04-08 15:18:55 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright (C) Igor Sysoev |
| 4 | */ |
| 5 | |
| 6 | |
| 7 | #ifndef _NGX_HASH_H_INCLUDED_ |
| 8 | #define _NGX_HASH_H_INCLUDED_ |
| 9 | |
| 10 | |
| 11 | #include <ngx_config.h> |
| 12 | #include <ngx_core.h> |
| 13 | |
| 14 | |
| 15 | typedef struct { |
Igor Sysoev | 2402502 | 2005-12-16 15:07:08 +0000 | [diff] [blame] | 16 | void *value; |
| 17 | u_char len; |
| 18 | u_char name[1]; |
| 19 | } ngx_hash_elt_t; |
Igor Sysoev | 02f742b | 2005-04-08 15:18:55 +0000 | [diff] [blame] | 20 | |
Igor Sysoev | 2402502 | 2005-12-16 15:07:08 +0000 | [diff] [blame] | 21 | |
| 22 | typedef struct { |
| 23 | ngx_hash_elt_t **buckets; |
| 24 | ngx_uint_t size; |
Igor Sysoev | 02f742b | 2005-04-08 15:18:55 +0000 | [diff] [blame] | 25 | } ngx_hash_t; |
| 26 | |
| 27 | |
| 28 | typedef struct { |
Igor Sysoev | 2402502 | 2005-12-16 15:07:08 +0000 | [diff] [blame] | 29 | ngx_hash_t hash; |
| 30 | void *value; |
| 31 | } ngx_hash_wildcard_t; |
| 32 | |
| 33 | |
| 34 | typedef struct { |
| 35 | ngx_str_t key; |
| 36 | ngx_uint_t key_hash; |
| 37 | void *value; |
| 38 | } ngx_hash_key_t; |
| 39 | |
| 40 | |
| 41 | typedef ngx_uint_t (*ngx_hash_key_pt) (u_char *data, size_t len); |
| 42 | |
| 43 | |
| 44 | typedef struct { |
Igor Sysoev | 9d8a75c | 2007-06-11 19:49:22 +0000 | [diff] [blame] | 45 | ngx_hash_t hash; |
| 46 | ngx_hash_wildcard_t *wc_head; |
| 47 | ngx_hash_wildcard_t *wc_tail; |
| 48 | } ngx_hash_combined_t; |
| 49 | |
| 50 | |
| 51 | typedef struct { |
Igor Sysoev | 2402502 | 2005-12-16 15:07:08 +0000 | [diff] [blame] | 52 | ngx_hash_t *hash; |
| 53 | ngx_hash_key_pt key; |
| 54 | |
| 55 | ngx_uint_t max_size; |
| 56 | ngx_uint_t bucket_size; |
| 57 | |
| 58 | char *name; |
| 59 | ngx_pool_t *pool; |
| 60 | ngx_pool_t *temp_pool; |
| 61 | } ngx_hash_init_t; |
| 62 | |
| 63 | |
Igor Sysoev | 305a9d8 | 2005-12-26 17:07:48 +0000 | [diff] [blame] | 64 | #define NGX_HASH_SMALL 1 |
| 65 | #define NGX_HASH_LARGE 2 |
| 66 | |
| 67 | #define NGX_HASH_LARGE_ASIZE 16384 |
| 68 | #define NGX_HASH_LARGE_HSIZE 10007 |
| 69 | |
| 70 | #define NGX_HASH_WILDCARD_KEY 1 |
Igor Sysoev | df3254a | 2006-01-11 15:26:57 +0000 | [diff] [blame] | 71 | #define NGX_HASH_READONLY_KEY 2 |
Igor Sysoev | 305a9d8 | 2005-12-26 17:07:48 +0000 | [diff] [blame] | 72 | |
| 73 | |
| 74 | typedef struct { |
| 75 | ngx_uint_t hsize; |
| 76 | |
| 77 | ngx_pool_t *pool; |
| 78 | ngx_pool_t *temp_pool; |
| 79 | |
| 80 | ngx_array_t keys; |
| 81 | ngx_array_t *keys_hash; |
| 82 | |
Igor Sysoev | 9d8a75c | 2007-06-11 19:49:22 +0000 | [diff] [blame] | 83 | ngx_array_t dns_wc_head; |
| 84 | ngx_array_t *dns_wc_head_hash; |
| 85 | |
| 86 | ngx_array_t dns_wc_tail; |
| 87 | ngx_array_t *dns_wc_tail_hash; |
Igor Sysoev | 305a9d8 | 2005-12-26 17:07:48 +0000 | [diff] [blame] | 88 | } ngx_hash_keys_arrays_t; |
| 89 | |
| 90 | |
Igor Sysoev | 2402502 | 2005-12-16 15:07:08 +0000 | [diff] [blame] | 91 | typedef struct { |
Igor Sysoev | 2402502 | 2005-12-16 15:07:08 +0000 | [diff] [blame] | 92 | ngx_uint_t hash; |
| 93 | ngx_str_t key; |
| 94 | ngx_str_t value; |
Igor Sysoev | 3338cfd | 2006-05-11 14:43:47 +0000 | [diff] [blame] | 95 | u_char *lowcase_key; |
Igor Sysoev | 02f742b | 2005-04-08 15:18:55 +0000 | [diff] [blame] | 96 | } ngx_table_elt_t; |
| 97 | |
| 98 | |
Igor Sysoev | 2402502 | 2005-12-16 15:07:08 +0000 | [diff] [blame] | 99 | void *ngx_hash_find(ngx_hash_t *hash, ngx_uint_t key, u_char *name, size_t len); |
Igor Sysoev | 9d8a75c | 2007-06-11 19:49:22 +0000 | [diff] [blame] | 100 | void *ngx_hash_find_wc_head(ngx_hash_wildcard_t *hwc, u_char *name, size_t len); |
| 101 | void *ngx_hash_find_wc_tail(ngx_hash_wildcard_t *hwc, u_char *name, size_t len); |
| 102 | void *ngx_hash_find_combined(ngx_hash_combined_t *hash, ngx_uint_t key, |
| 103 | u_char *name, size_t len); |
Igor Sysoev | 2402502 | 2005-12-16 15:07:08 +0000 | [diff] [blame] | 104 | |
| 105 | ngx_int_t ngx_hash_init(ngx_hash_init_t *hinit, ngx_hash_key_t *names, |
| 106 | ngx_uint_t nelts); |
| 107 | ngx_int_t ngx_hash_wildcard_init(ngx_hash_init_t *hinit, ngx_hash_key_t *names, |
| 108 | ngx_uint_t nelts); |
| 109 | |
Igor Sysoev | 3338cfd | 2006-05-11 14:43:47 +0000 | [diff] [blame] | 110 | #define ngx_hash(key, c) ((ngx_uint_t) key * 31 + c) |
Igor Sysoev | 2402502 | 2005-12-16 15:07:08 +0000 | [diff] [blame] | 111 | ngx_uint_t ngx_hash_key(u_char *data, size_t len); |
| 112 | ngx_uint_t ngx_hash_key_lc(u_char *data, size_t len); |
Igor Sysoev | 6a07833 | 2008-08-04 10:18:36 +0000 | [diff] [blame] | 113 | ngx_uint_t ngx_hash_strlow(u_char *dst, u_char *src, size_t n); |
| 114 | |
Igor Sysoev | 2402502 | 2005-12-16 15:07:08 +0000 | [diff] [blame] | 115 | |
Igor Sysoev | 305a9d8 | 2005-12-26 17:07:48 +0000 | [diff] [blame] | 116 | ngx_int_t ngx_hash_keys_array_init(ngx_hash_keys_arrays_t *ha, ngx_uint_t type); |
| 117 | ngx_int_t ngx_hash_add_key(ngx_hash_keys_arrays_t *ha, ngx_str_t *key, |
| 118 | void *value, ngx_uint_t flags); |
| 119 | |
Igor Sysoev | 2402502 | 2005-12-16 15:07:08 +0000 | [diff] [blame] | 120 | |
Igor Sysoev | 02f742b | 2005-04-08 15:18:55 +0000 | [diff] [blame] | 121 | #endif /* _NGX_HASH_H_INCLUDED_ */ |