summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_array.h
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2017-01-17 20:00:00 +0300
committerIgor Sysoev <igor@sysoev.ru>2017-01-17 20:00:00 +0300
commit16cbf3c076a0aca6d47adaf3f719493674cf2363 (patch)
treee6530480020f62a2bdbf249988ec3e2a751d3927 /src/nxt_array.h
downloadunit-16cbf3c076a0aca6d47adaf3f719493674cf2363.tar.gz
unit-16cbf3c076a0aca6d47adaf3f719493674cf2363.tar.bz2
Initial version.
Diffstat (limited to 'src/nxt_array.h')
-rw-r--r--src/nxt_array.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/nxt_array.h b/src/nxt_array.h
new file mode 100644
index 00000000..491572da
--- /dev/null
+++ b/src/nxt_array.h
@@ -0,0 +1,51 @@
+
+/*
+ * Copyright (C) Igor Sysoev
+ * Copyright (C) NGINX, Inc.
+ */
+
+#ifndef _NXT_ARRAY_H_INCLUDED_
+#define _NXT_ARRAY_H_INCLUDED_
+
+
+typedef struct {
+ void *elts;
+ /* nelts has uint32_t type because it is used most often. */
+ uint32_t nelts;
+ uint16_t size;
+ uint16_t nalloc;
+ nxt_mem_pool_t *mem_pool;
+} nxt_array_t;
+
+
+NXT_EXPORT nxt_array_t *nxt_array_create(nxt_mem_pool_t *mp, nxt_uint_t n,
+ size_t size);
+NXT_EXPORT void *nxt_array_add(nxt_array_t *array);
+NXT_EXPORT void *nxt_array_zero_add(nxt_array_t *array);
+NXT_EXPORT void nxt_array_remove(nxt_array_t *array, void *elt);
+
+
+#define \
+nxt_array_last(array) \
+ ((void *) ((char *) (array)->elts + (array)->size * ((array)->nelts - 1)))
+
+
+#define \
+nxt_array_reset(array) \
+ (array)->nelts = 0;
+
+
+#define \
+nxt_array_is_empty(array) \
+ ((array)->nelts == 0)
+
+
+nxt_inline void *
+nxt_array_remove_last(nxt_array_t *array)
+{
+ array->nelts--;
+ return (char *) array->elts + array->size * array->nelts;
+}
+
+
+#endif /* _NXT_ARRAY_H_INCLUDED_ */