Back to home page

Nginx displayed by LXR

Source navigation ]
Diff markup ]
Identifier search ]
general search ]
 
 
Version: nginx-1.15.12 ]​[ nginx-1.16.0 ]​

0001 
0002 /*
0003  * Copyright (C) Igor Sysoev
0004  * Copyright (C) Nginx, Inc.
0005  */
0006 
0007 
0008 #ifndef _NGX_RBTREE_H_INCLUDED_
0009 #define _NGX_RBTREE_H_INCLUDED_
0010 
0011 
0012 #include <ngx_config.h>
0013 #include <ngx_core.h>
0014 
0015 
0016 typedef ngx_uint_t  ngx_rbtree_key_t;
0017 typedef ngx_int_t   ngx_rbtree_key_int_t;
0018 
0019 
0020 typedef struct ngx_rbtree_node_s  ngx_rbtree_node_t;
0021 
0022 struct ngx_rbtree_node_s {
0023     ngx_rbtree_key_t       key;
0024     ngx_rbtree_node_t     *left;
0025     ngx_rbtree_node_t     *right;
0026     ngx_rbtree_node_t     *parent;
0027     u_char                 color;
0028     u_char                 data;
0029 };
0030 
0031 
0032 typedef struct ngx_rbtree_s  ngx_rbtree_t;
0033 
0034 typedef void (*ngx_rbtree_insert_pt) (ngx_rbtree_node_t *root,
0035     ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel);
0036 
0037 struct ngx_rbtree_s {
0038     ngx_rbtree_node_t     *root;
0039     ngx_rbtree_node_t     *sentinel;
0040     ngx_rbtree_insert_pt   insert;
0041 };
0042 
0043 
0044 #define ngx_rbtree_init(tree, s, i)                                           \
0045     ngx_rbtree_sentinel_init(s);                                              \
0046     (tree)->root = s;                                                         \
0047     (tree)->sentinel = s;                                                     \
0048     (tree)->insert = i
0049 
0050 
0051 void ngx_rbtree_insert(ngx_rbtree_t *tree, ngx_rbtree_node_t *node);
0052 void ngx_rbtree_delete(ngx_rbtree_t *tree, ngx_rbtree_node_t *node);
0053 void ngx_rbtree_insert_value(ngx_rbtree_node_t *root, ngx_rbtree_node_t *node,
0054     ngx_rbtree_node_t *sentinel);
0055 void ngx_rbtree_insert_timer_value(ngx_rbtree_node_t *root,
0056     ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel);
0057 ngx_rbtree_node_t *ngx_rbtree_next(ngx_rbtree_t *tree,
0058     ngx_rbtree_node_t *node);
0059 
0060 
0061 #define ngx_rbt_red(node)               ((node)->color = 1)
0062 #define ngx_rbt_black(node)             ((node)->color = 0)
0063 #define ngx_rbt_is_red(node)            ((node)->color)
0064 #define ngx_rbt_is_black(node)          (!ngx_rbt_is_red(node))
0065 #define ngx_rbt_copy_color(n1, n2)      (n1->color = n2->color)
0066 
0067 
0068 /* a sentinel must be black */
0069 
0070 #define ngx_rbtree_sentinel_init(node)  ngx_rbt_black(node)
0071 
0072 
0073 static ngx_inline ngx_rbtree_node_t *
0074 ngx_rbtree_min(ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel)
0075 {
0076     while (node->left != sentinel) {
0077         node = node->left;
0078     }
0079 
0080     return node;
0081 }
0082 
0083 
0084 #endif /* _NGX_RBTREE_H_INCLUDED_ */