xref: /unit/src/nxt_array.h (revision 65:10688b89aa16)
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_add(nxt_array_t *array);
24 NXT_EXPORT void *nxt_array_zero_add(nxt_array_t *array);
25 NXT_EXPORT void nxt_array_remove(nxt_array_t *array, void *elt);
26 
27 
28 #define                                                                       \
29 nxt_array_last(array)                                                         \
30     ((void *) ((char *) (array)->elts + (array)->size * ((array)->nelts - 1)))
31 
32 
33 #define                                                                       \
34 nxt_array_reset(array)                                                        \
35     (array)->nelts = 0;
36 
37 
38 #define                                                                       \
39 nxt_array_is_empty(array)                                                     \
40     ((array)->nelts == 0)
41 
42 
43 nxt_inline void *
44 nxt_array_remove_last(nxt_array_t *array)
45 {
46     array->nelts--;
47     return (char *) array->elts + array->size * array->nelts;
48 }
49 
50 
51 #endif /* _NXT_ARRAY_H_INCLUDED_ */
52