Src/core/ngx_queue. {C|h} implements a queue 's operational logic, with the basic structure of the queue as a two-way queue
The underlying data structure is:
[CPP] View plaincopyprint?
- typedef struct ngx_queue_s ngx_queue_t;
- struct ngx_queue_s {
- ngx_queue_t *prev;
- ngx_queue_t *next;
- };
According to the data structure can be found, nginx queue operation and structure only pointer operation, not responsible for node content space allocation and preservation, so in the definition of their own queue node, you need to define the data structure and allocation of space, and contains a member of the ngx_queue_t type, you need to use the Ngx_queue_data macro when you want to get the original data node:
[CPP] View plaincopyprint?
- Src/core/ngx_queue.h
- #define NGX_QUEUE_DATA (q, type, link) (Type *) ((U_char *) q-offsetof (type, link))
In addition, the entire queue structure contains a Sentinel sentinel node that points to the head and tail of the queue .
Look at the next queue. The source Discovery Implementation section has only two methods:
[CPP] View plaincopyprint?
- ngx_queue_t * Ngx_queue_middle (ngx_queue_t *queue) //Find the middle queue
- void Ngx_queue_sort (ngx_queue_t *queue, ngx_int_t (*cmp) (const ngx_queue_t *, const ngx_queue_t *) //seems to be the insertion sort ,//There is not much to see
ngx_queue_init Initialize queue
ngx_queue_empty all nodes in a node before a node is emptied
ngx_queue_insert_head Inserting a node after the specified node
ngx_queue_insert_after Inserting a node after the specified node
ngx_queue_insert_tail Inserting a node before the specified node
Ngx_queue_head Get the next node of the node
Ngx_queue_next Get the next node of the node
ngx_queue_last Get the previous node of the node
Ngx_queue_prev Get the previous node of the node
Ngx_queue_sentinel Get the current node
ngx_queue_remove Delete a node in a queue
ngx_queue_data getting data for a node in a queue
Ngx_queue_split
Ngx_queue_add
Ngx_queue_middle
Ngx_queue_sort
The above describes the Nginx source learning Note (ix)-The basic container--queue, including the queue, insert sorting content, I hope to be interested in PHP tutorial friends helpful.