#include <stdlib.h> // for malloc, realloc, free, qsort
-#include <string.h> // for memmove, memcpy
+#include <string.h> // for memmove, memcpy, memcmp
#include "array.h"
#include "bits/callback.h" // for Comparator
memcpy(array->ptr + oldsiz * array->mbs, ptr, array->mbs);
}
+ssize_t array_idx(Array *array, const void *ptr)
+{
+ for (size_t i = 0; i < array->siz; i++)
+ if (memcmp(array->ptr + i * array->mbs, ptr, array->mbs) == 0)
+ return i;
+
+ return -1;
+}
+
void array_cpy(Array *array, void **ptr, size_t *n)
{
*n = array->siz;
but it is slightly faster since it saves unnecessary calls.
*/
+ssize_t array_idx(Array *array, const void *ptr);
+/*
+ Returns the index of the first element that equals ptr, or none if no matches.
+
+ Uses memcmp to compare the elements.
+*/
+
void array_cpy(Array *array, void **ptr, size_t *n);
/*
Allocates a buffer big enough to fit the array's used size.