-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathngx_map.h
131 lines (105 loc) · 2.78 KB
/
ngx_map.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
* Copyright (C) AlexWoo(Wu Jie) [email protected]
*/
#ifndef _NGX_MAP_H_INCLUDED_
#define _NGX_MAP_H_INCLUDED_
#include <ngx_config.h>
#include <ngx_core.h>
/*
* key: key for map node
*/
typedef ngx_rbtree_key_t (* ngx_map_hash_pt)(intptr_t key);
/*
* if key1 < key2, return -1
* if key1 = key2, return 0
* if key1 > key2, return 1
*/
typedef int (* ngx_cmp_pt)(intptr_t key1, intptr_t key2);
/* ngx_str_t */
ngx_rbtree_key_t ngx_map_hash_str(intptr_t key);
int ngx_cmp_str(intptr_t key1, intptr_t key2);
/* ngx_uint_t */
ngx_rbtree_key_t ngx_map_hash_uint(intptr_t key);
int ngx_cmp_uint(intptr_t key1, intptr_t key2);
/* ngx_int_t */
ngx_rbtree_key_t ngx_map_hash_int(intptr_t key);
int ngx_cmp_int(intptr_t key1, intptr_t key2);
typedef struct {
ngx_rbtree_t rbtree;
ngx_rbtree_node_t sentinel;
ngx_map_hash_pt hash;
ngx_cmp_pt cmp;
} ngx_map_t;
typedef struct {
ngx_rbtree_node_t rn;
intptr_t raw_key;
ngx_map_t *map;
} ngx_map_node_t;
/*
* return value:
* None
* paras:
* map : map for initial
* hash: hash func for calc key's hash
* cmp : cmp func for cmp two keys
*/
void ngx_map_init(ngx_map_t *map, ngx_map_hash_pt hash, ngx_cmp_pt cmp);
/*
* return value:
* if map is empty return 1, else return 0
*/
#define ngx_map_empty(map) (map->rbtree.root == map->rbtree.sentinel)
/*
* return value:
* the mininum key map node, if map is empty, return NULL
* paras:
* map: map for operate
*/
ngx_map_node_t *ngx_map_begin(ngx_map_t *map);
/*
* return value:
* the maximum key map node, if map is empty, return NULL
* paras:
* map: map for operate
*/
ngx_map_node_t *ngx_map_rbegin(ngx_map_t *map);
/*
* return value:
* the next bigger key map node, if none, return NULL
* paras:
* n : current node
*/
ngx_map_node_t *ngx_map_next(ngx_map_node_t *n);
/*
* return value:
* the next smaller key map node, if none, return NULL
* paras:
* n : current node
*/
ngx_map_node_t *ngx_map_prev(ngx_map_node_t *n);
/*
* return value:
* None
* paras:
* map : map for operate
* node : map node for inserting into map
* covered: 1 for covered if key is same, 0 do nothing if key is same
*/
void ngx_map_insert(ngx_map_t *map, ngx_map_node_t *node, ngx_flag_t covered);
/*
* return value:
* None
* paras:
* map: map for operate
* key: map node key for deleting from map
*/
void ngx_map_delete(ngx_map_t *map, intptr_t key);
/*
* return value:
* node in map searching by key, NULL for not found
* paras:
* map: map for operate
* key: node key for searching
*/
ngx_map_node_t *ngx_map_find(ngx_map_t *map, intptr_t key);
#endif