xref: /unit/src/nxt_array.h (revision 1489:4a3ec07f4b19)
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 NXT_EXPORT nxt_array_t *nxt_array_copy(nxt_mp_t *mp, nxt_array_t *dst,
28     nxt_array_t *src);
29 
30 #define                                                                       \
31 nxt_array_last(array)                                                         \
32     nxt_pointer_to((array)->elts, (array)->size * ((array)->nelts - 1))
33 
34 
35 #define                                                                       \
36 nxt_array_reset(array)                                                        \
37     (array)->nelts = 0;
38 
39 
40 #define                                                                       \
41 nxt_array_is_empty(array)                                                     \
42     ((array)->nelts == 0)
43 
44 
45 nxt_inline void *
46 nxt_array_remove_last(nxt_array_t *array)
47 {
48     array->nelts--;
49     return nxt_pointer_to(array->elts, array->size * array->nelts);
50 }
51 
52 
53 #endif /* _NXT_ARRAY_H_INCLUDED_ */
54