blob: 75db868868669bab570d169b81908449d7d79a35 [file] [log] [blame]
Igor Sysoevd90282d2004-09-28 08:34:51 +00001
2/*
Igor Sysoevff8da912004-09-29 16:00:49 +00003 * Copyright (C) Igor Sysoev
Igor Sysoevd90282d2004-09-28 08:34:51 +00004 */
5
6
Igor Sysoevb9e34412004-09-03 15:50:30 +00007#ifndef _NGX_LIST_H_INCLUDED_
8#define _NGX_LIST_H_INCLUDED_
9
10
11#include <ngx_config.h>
12#include <ngx_core.h>
13
14
15typedef struct ngx_list_part_s ngx_list_part_t;
16
17struct ngx_list_part_s {
18 void *elts;
19 ngx_uint_t nelts;
20 ngx_list_part_t *next;
21};
22
23
24typedef struct {
25 ngx_list_part_t *last;
26 ngx_list_part_t part;
27 size_t size;
28 ngx_uint_t nalloc;
29 ngx_pool_t *pool;
30} ngx_list_t;
31
32
Igor Sysoev35d52722006-10-11 12:47:11 +000033ngx_list_t *ngx_list_create(ngx_pool_t *pool, ngx_uint_t n, size_t size);
34
35static ngx_inline ngx_int_t
36ngx_list_init(ngx_list_t *list, ngx_pool_t *pool, ngx_uint_t n, size_t size)
Igor Sysoev980a9242004-09-05 19:54:02 +000037{
Igor Sysoevc1571722005-03-19 12:38:37 +000038 list->part.elts = ngx_palloc(pool, n * size);
39 if (list->part.elts == NULL) {
Igor Sysoev980a9242004-09-05 19:54:02 +000040 return NGX_ERROR;
41 }
42
43 list->part.nelts = 0;
44 list->part.next = NULL;
45 list->last = &list->part;
46 list->size = size;
47 list->nalloc = n;
48 list->pool = pool;
49
50 return NGX_OK;
51}
Igor Sysoevb9e34412004-09-03 15:50:30 +000052
53
Igor Sysoev980a9242004-09-05 19:54:02 +000054/*
55 *
56 * the iteration through the list:
57 *
58 * part = &list.part;
59 * data = part->elts;
60 *
61 * for (i = 0 ;; i++) {
62 *
63 * if (i >= part->nelts) {
64 * if (part->next == NULL) {
65 * break;
66 * }
67 *
68 * part = part->next;
69 * data = part->elts;
70 * i = 0;
71 * }
72 *
73 * ... data[i] ...
74 *
75 * }
76 */
Igor Sysoevb9e34412004-09-03 15:50:30 +000077
78
Igor Sysoevaab4d8c2004-09-06 18:45:00 +000079void *ngx_list_push(ngx_list_t *list);
Igor Sysoevb9e34412004-09-03 15:50:30 +000080
81
82#endif /* _NGX_LIST_H_INCLUDED_ */