summaryrefslogtreecommitdiff
path: root/arr.c
diff options
context:
space:
mode:
Diffstat (limited to 'arr.c')
-rw-r--r--arr.c30
1 files changed, 8 insertions, 22 deletions
diff --git a/arr.c b/arr.c
index d092e68..2ca394c 100644
--- a/arr.c
+++ b/arr.c
@@ -1,27 +1,5 @@
#ifndef ARR_C_
#define ARR_C_
-/*
-This is free and unencumbered software released into the public domain.
-Anyone is free to copy, modify, publish, use, compile, sell, or
-distribute this software, either in source code form or as a compiled
-binary, for any purpose, commercial or non-commercial, and by any
-means.
-In jurisdictions that recognize copyright laws, the author or authors
-of this software dedicate any and all copyright interest in the
-software to the public domain. We make this dedication for the benefit
-of the public at large and to the detriment of our heirs and
-successors. We intend this dedication to be an overt act of
-relinquishment in perpetuity of all present and future rights to this
-software under copyright law.
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-For more information, please refer to <http://unlicense.org/>
-*/
// functions in this file suffixed with _ are not meant to be used outside here, unless you
// know what you're doing
@@ -29,6 +7,9 @@ For more information, please refer to <http://unlicense.org/>
// IMPORTANT NOTE: If you are using this with structures containing `long double`s, do
// #define ARR_LONG_DOUBLE
// before including this file
+// ( otherwise the long doubles will not be aligned.
+// this does mean that arrays waste 8 bytes of memory.
+// which isnt important unless you're making a lot of arrays.)
#include <stddef.h>
typedef union {
@@ -60,6 +41,10 @@ static inline u32 arr_len(void *arr) {
return arr ? arr_hdr_(arr)->len : 0;
}
+static inline u32 arr_cap(void *arr) {
+ return arr ? arr_hdr_(arr)->cap : 0;
+}
+
static inline unsigned arr_lenu(void *arr) {
return (unsigned)arr_len(arr);
}
@@ -114,6 +99,7 @@ static void arr_reserve_(void **arr, size_t member_size, size_t n) {
if (!*arr) {
// create a new array with capacity n+1
+ // why n+1? i dont know i wrote this a while ago
ArrHeader *hdr = calloc(1, sizeof(ArrHeader) + (n+1) * member_size);
if (hdr) {
hdr->cap = (u32)n+1;