--- /dev/null
+#ifndef CONTAINER_H
+#define CONTAINER_H
+
+#include "types.h"
+#include <assert.h>
+
+template <typename T>
+struct Array
+{
+ u32 count;
+ u32 capacity;
+ T *data;
+
+ Array()
+ {
+ count = 0;
+ capacity = 0;
+ data = nullptr;
+ }
+
+ T& operator[](i32 elem) {
+#if defined(DEBUG)
+ assert(elem >= 0 && elem < count);
+#endif
+ return data[elem];
+ }
+ const T& operator[](i32 elem) const { return data[elem]; }
+
+ bool ensure_capacity(u32 min_capacity)
+ {
+ if (min_capacity <= capacity) return true;
+
+ u32 new_capacity = 0;
+ if (data != nullptr)
+ {
+ new_capacity = capacity;
+ while (new_capacity < min_capacity) new_capacity <<= 1;
+
+ data = (T*) realloc(data, new_capacity * sizeof(T));
+ }
+ else
+ {
+ new_capacity = min_capacity;
+ data = (T*) malloc(new_capacity * sizeof(T));
+ }
+
+ if (data == nullptr) return false;
+
+ capacity = new_capacity;
+ return true;
+ }
+
+ void push(const T& val)
+ {
+ if (!ensure_capacity(count + 1)) return;
+ data[count++] = val;
+ }
+
+ T pop()
+ {
+ return data[--count];
+ }
+
+ void clear()
+ {
+ count = 0;
+ }
+
+ void insert(u32 idx, const T& x)
+ {
+ if (!ensure_capacity(count + 1)) return;
+
+ count += 1;
+ for (u32 i = count; i > idx; i--)
+ data[i] = data[i - 1];
+
+ data[idx] = x;
+ }
+
+ void remove(const T& elem)
+ {
+ auto move = 0;
+
+ for (u32 i = 0; i < count - move; i++)
+ {
+ if (data[i + move] == elem) move += 1;
+ if (move != 0) data[i] = data[i + move];
+ }
+
+ count -= move;
+ }
+
+ void delete_at(u32 idx)
+ {
+ if (idx >= count) return;
+
+ for (u32 i = idx; i < count - 1; i++)
+ data[i] = data[i + 1];
+
+ count -= 1;
+ }
+
+ void fast_delete(u32 idx)
+ {
+ if (idx >= count) return;
+
+ data[idx] = data[count - 1];
+ count -= 1;
+ }
+
+ bool contains(const T& x)
+ {
+ for (u32 i = 0; i < count; i++)
+ {
+ if (data[i] == x) return true;
+ }
+
+ return false;
+ }
+
+
+ T* begin()
+ {
+ return &data[0];
+ }
+
+ T* end()
+ {
+ return &data[count];
+ }
+};
+
+#endif //CONTAINER_H
#include <stdint.h> // NOTE(Brendan): Only for intptr_t
// NOTE(Brendan): Hacky way to get the offset of a struct member. offsetof() is the standard way in C to get it, but it is not guarenteed to be defined in all C implementations.
-#define offset_of(S, mem) (intptr_t) &(((S*)(0))->mem)
+// #define offset_of(S, mem) (intptr_t) &(((S*)(0))->mem)
// NOTE(Brendan): There are so many uses of 'static' in C and they quickly lose their meaning.
#define internal static // internal void foo() { ... }