xref: /unit/src/nxt_array.h (revision 146:24354fd871d5)
1 
2 /*
3  * Copyright (C) Igor Sysoev
4  * Copyright (C) NGINX, Inc.
5  */
6 
7 #ifndef _NXT_ARRAY_H_INCLUDED_
8 #define _NXT_ARRAY_H_INCLUDED_
9 
10 
11 typedef struct {
12     void      *elts;
13     /* nelts has uint32_t type because it is used most often. */
14     uint32_t  nelts;
15     uint16_t  size;
16     uint16_t  nalloc;
17     nxt_mp_t  *mem_pool;
18 } nxt_array_t;
19 
20 
21 NXT_EXPORT nxt_array_t *nxt_array_create(nxt_mp_t *mp, nxt_uint_t n,
22     size_t size);
23 NXT_EXPORT void nxt_array_destroy(nxt_array_t *array);
24 NXT_EXPORT void *nxt_array_add(nxt_array_t *array);
25 NXT_EXPORT void *nxt_array_zero_add(nxt_array_t *array);
26 NXT_EXPORT void nxt_array_remove(nxt_array_t *array, void *elt);
27 
28 
29 #define                                                                       \
30 nxt_array_last(array)                                                         \
31     nxt_pointer_to((array)->elts, (array)->size * ((array)->nelts - 1))
32 
33 
34 #define                                                                       \
35 nxt_array_reset(array)                                                        \
36     (array)->nelts = 0;
37 
38 
39 #define                                                                       \
40 nxt_array_is_empty(array)                                                     \
41     ((array)->nelts == 0)
42 
43 
44 nxt_inline void *
45 nxt_array_remove_last(nxt_array_t *array)
46 {
47     array->nelts--;
48     return nxt_pointer_to(array->elts, array->size * array->nelts);
49 }
50 
51 
52 #endif /* _NXT_ARRAY_H_INCLUDED_ */
53