summaryrefslogtreecommitdiff
path: root/src/array.cc
blob: 7c8cc19c0c48a1abe2402b3d6d215615fbb229ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#ifndef ARRAY_CC
#define ARRAY_CC

#include "memory.cc"

#define ARRAY_INIT 4
#define ARRAY_GROWTH 2

template <typename T>
struct Array {
  Slice<T> buffer;
  const Allocator* allocator;
};

#define array_init(T, allocator) Array<T>{Slice<T>{}, allocator}

template<typename T>
void array_deinit(Array<T>* array) {
  assert(array != nullptr);

  if(unlikely(array->allocator == nullptr)) return;

  slice_deallocate(array->allocator, &array->buffer);
  array->allocator = nullptr;
}

#endif