summaryrefslogtreecommitdiffstats
path: root/darray.h
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2022-01-18 12:01:56 -0500
committerTavian Barnes <tavianator@tavianator.com>2022-01-18 12:27:29 -0500
commit6ac4deb451ccd4ed11fb0d022b83710b5b0522fe (patch)
treed1cc49bd9abca1aaa91c5a990e1cb521f5fa09ee /darray.h
parent60dc18c9fcb2550e15a35809818764ee43a178c7 (diff)
downloadbfs-6ac4deb451ccd4ed11fb0d022b83710b5b0522fe.tar.xz
darray: New DARRAY_POP() macro
Diffstat (limited to 'darray.h')
-rw-r--r--darray.h25
1 files changed, 24 insertions, 1 deletions
diff --git a/darray.h b/darray.h
index 6ab8199..e2d0e10 100644
--- a/darray.h
+++ b/darray.h
@@ -1,6 +1,6 @@
/****************************************************************************
* bfs *
- * Copyright (C) 2019 Tavian Barnes <tavianator@tavianator.com> *
+ * Copyright (C) 2019-2022 Tavian Barnes <tavianator@tavianator.com> *
* *
* Permission to use, copy, modify, and/or distribute this software for any *
* purpose with or without fee is hereby granted. *
@@ -87,6 +87,18 @@ void *darray_push(void *da, const void *item, size_t size);
int darray_check(void *da);
/**
+ * @internal Use DARRAY_POP().
+ *
+ * Pop an element from an array.
+ *
+ * @param da
+ * The array in question.
+ * @return
+ * The (new) length of the array.
+ */
+size_t darray_pop(void *da);
+
+/**
* Free a darray.
*
* @param da
@@ -107,4 +119,15 @@ void darray_free(void *da);
#define DARRAY_PUSH(da, item) \
(darray_check(*(da) = darray_push(*(da), (item), sizeof(**(da) = *(item)))))
+/**
+ * Pop an item from a darray.
+ *
+ * @param da
+ * The array to pop from.
+ * @return
+ * The popped item.
+ */
+#define DARRAY_POP(da) \
+ ((da)[darray_pop((da))])
+
#endif // BFS_DARRAY_H