Update android/utils/ with misc. new features.
This introduces a few new features to android/utils/ that will
be used in later patches.
+ <android/utils/assert.h> to handle assertions
+ <android/utils/vector.h> to handle dynamic arrays
+ <android/utils/reflist.h> slightly updated (more docs)
+ <android/utils/refset.h> implements a set of pointers
Change-Id: Iebc14cfefd1c0e8aaecda9958a980d40f0be610a
diff --git a/android/utils/vector.c b/android/utils/vector.c
new file mode 100644
index 0000000..9029d05
--- /dev/null
+++ b/android/utils/vector.c
@@ -0,0 +1,33 @@
+#include <android/utils/vector.h>
+#include <limits.h>
+
+extern void
+_avector_ensure( void** items, size_t itemSize, unsigned* pMaxItems, unsigned newCount )
+{
+ unsigned oldMax = *pMaxItems;
+
+ if (newCount > oldMax) {
+ unsigned newMax = oldMax;
+ unsigned bigMax = UINT_MAX / itemSize;
+
+ if (itemSize == 0) {
+ AASSERT_FAIL("trying to reallocate array of 0-size items (count=%d)\n", newCount);
+ }
+
+ if (newCount > bigMax) {
+ AASSERT_FAIL("trying to reallocate over-sized array of %d-bytes items (%d > %d)\n",
+ itemSize, newCount, bigMax);
+ }
+
+ while (newMax < newCount) {
+ unsigned newMax2 = newMax + (newMax >> 1) + 4;
+ if (newMax2 < newMax || newMax2 > bigMax)
+ newMax2 = bigMax;
+ newMax = newMax2;
+ }
+
+ *items = _android_array_realloc( *items, itemSize, newMax );
+ *pMaxItems = newMax;
+ }
+}
+