Mercurial > hg > nginx
annotate src/core/ngx_rbtree.h @ 3513:e60e00b4fe0c
ngx_http_split_clients_module
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 14 May 2010 09:02:10 +0000 |
parents | 33c2e3c6f02c |
children | d620f497c50f |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
209
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
209
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
209
diff
changeset
|
4 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
209
diff
changeset
|
5 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
209
diff
changeset
|
6 |
205
4a9a2b1dd6fa
nginx-0.0.1-2003-12-04-17:53:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 #ifndef _NGX_RBTREE_H_INCLUDED_ |
4a9a2b1dd6fa
nginx-0.0.1-2003-12-04-17:53:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #define _NGX_RBTREE_H_INCLUDED_ |
4a9a2b1dd6fa
nginx-0.0.1-2003-12-04-17:53:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 |
4a9a2b1dd6fa
nginx-0.0.1-2003-12-04-17:53:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
4a9a2b1dd6fa
nginx-0.0.1-2003-12-04-17:53:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 #include <ngx_config.h> |
4a9a2b1dd6fa
nginx-0.0.1-2003-12-04-17:53:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
12 #include <ngx_core.h> |
4a9a2b1dd6fa
nginx-0.0.1-2003-12-04-17:53:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
13 |
4a9a2b1dd6fa
nginx-0.0.1-2003-12-04-17:53:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
14 |
557 | 15 typedef ngx_uint_t ngx_rbtree_key_t; |
16 typedef ngx_int_t ngx_rbtree_key_int_t; | |
17 | |
18 | |
559 | 19 typedef struct ngx_rbtree_node_s ngx_rbtree_node_t; |
205
4a9a2b1dd6fa
nginx-0.0.1-2003-12-04-17:53:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
20 |
559 | 21 struct ngx_rbtree_node_s { |
22 ngx_rbtree_key_t key; | |
23 ngx_rbtree_node_t *left; | |
24 ngx_rbtree_node_t *right; | |
25 ngx_rbtree_node_t *parent; | |
853 | 26 u_char color; |
27 u_char data; | |
205
4a9a2b1dd6fa
nginx-0.0.1-2003-12-04-17:53:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
28 }; |
4a9a2b1dd6fa
nginx-0.0.1-2003-12-04-17:53:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
29 |
207
6e0fef527732
nginx-0.0.1-2003-12-05-20:07:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
206
diff
changeset
|
30 |
559 | 31 typedef struct ngx_rbtree_s ngx_rbtree_t; |
32 | |
853 | 33 typedef void (*ngx_rbtree_insert_pt) (ngx_rbtree_node_t *root, |
559 | 34 ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel); |
35 | |
36 struct ngx_rbtree_s { | |
37 ngx_rbtree_node_t *root; | |
38 ngx_rbtree_node_t *sentinel; | |
853 | 39 ngx_rbtree_insert_pt insert; |
559 | 40 }; |
205
4a9a2b1dd6fa
nginx-0.0.1-2003-12-04-17:53:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
41 |
4a9a2b1dd6fa
nginx-0.0.1-2003-12-04-17:53:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
42 |
1686 | 43 #define ngx_rbtree_init(tree, s, i) \ |
44 ngx_rbtree_sentinel_init(s); \ | |
45 (tree)->root = s; \ | |
46 (tree)->sentinel = s; \ | |
47 (tree)->insert = i | |
48 | |
49 | |
559 | 50 void ngx_rbtree_insert(ngx_thread_volatile ngx_rbtree_t *tree, |
51 ngx_rbtree_node_t *node); | |
52 void ngx_rbtree_delete(ngx_thread_volatile ngx_rbtree_t *tree, | |
53 ngx_rbtree_node_t *node); | |
861 | 54 void ngx_rbtree_insert_value(ngx_rbtree_node_t *root, ngx_rbtree_node_t *node, |
55 ngx_rbtree_node_t *sentinel); | |
853 | 56 void ngx_rbtree_insert_timer_value(ngx_rbtree_node_t *root, |
57 ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel); | |
559 | 58 |
59 | |
1023
68cc5e2e1a5d
make global the rbtree color handling macros
Igor Sysoev <igor@sysoev.ru>
parents:
965
diff
changeset
|
60 #define ngx_rbt_red(node) ((node)->color = 1) |
68cc5e2e1a5d
make global the rbtree color handling macros
Igor Sysoev <igor@sysoev.ru>
parents:
965
diff
changeset
|
61 #define ngx_rbt_black(node) ((node)->color = 0) |
68cc5e2e1a5d
make global the rbtree color handling macros
Igor Sysoev <igor@sysoev.ru>
parents:
965
diff
changeset
|
62 #define ngx_rbt_is_red(node) ((node)->color) |
68cc5e2e1a5d
make global the rbtree color handling macros
Igor Sysoev <igor@sysoev.ru>
parents:
965
diff
changeset
|
63 #define ngx_rbt_is_black(node) (!ngx_rbt_is_red(node)) |
68cc5e2e1a5d
make global the rbtree color handling macros
Igor Sysoev <igor@sysoev.ru>
parents:
965
diff
changeset
|
64 #define ngx_rbt_copy_color(n1, n2) (n1->color = n2->color) |
68cc5e2e1a5d
make global the rbtree color handling macros
Igor Sysoev <igor@sysoev.ru>
parents:
965
diff
changeset
|
65 |
68cc5e2e1a5d
make global the rbtree color handling macros
Igor Sysoev <igor@sysoev.ru>
parents:
965
diff
changeset
|
66 |
965 | 67 /* a sentinel must be black */ |
68 | |
1023
68cc5e2e1a5d
make global the rbtree color handling macros
Igor Sysoev <igor@sysoev.ru>
parents:
965
diff
changeset
|
69 #define ngx_rbtree_sentinel_init(node) ngx_rbt_black(node) |
965 | 70 |
71 | |
559 | 72 static ngx_inline ngx_rbtree_node_t * |
73 ngx_rbtree_min(ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel) | |
205
4a9a2b1dd6fa
nginx-0.0.1-2003-12-04-17:53:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
74 { |
557 | 75 while (node->left != sentinel) { |
76 node = node->left; | |
77 } | |
205
4a9a2b1dd6fa
nginx-0.0.1-2003-12-04-17:53:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
78 |
557 | 79 return node; |
205
4a9a2b1dd6fa
nginx-0.0.1-2003-12-04-17:53:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
80 } |
4a9a2b1dd6fa
nginx-0.0.1-2003-12-04-17:53:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
81 |
4a9a2b1dd6fa
nginx-0.0.1-2003-12-04-17:53:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
82 |
4a9a2b1dd6fa
nginx-0.0.1-2003-12-04-17:53:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
83 #endif /* _NGX_RBTREE_H_INCLUDED_ */ |