summaryrefslogtreecommitdiff
path: root/src/vec.h
blob: 2b4d11c675f2f3b3a85256178a59d45d5bd3e6c5 (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
28
29
30
31
32
33
34
35
36
37
38
#pragma once

#include "utils.h"

#define WAYC_VEC_INITIAL 4
#define WAYC_VEC_GROWTH 2
#define WAYC_VEC_THRESHOLD 8

struct raw_vec_s {
  u8 *ptr;
  usize size;
  usize len, cap;
};

#define WAYC_RAW_VEC_INIT(size) {nullptr, size, 0, 0}

void wayc_raw_vec_push(raw_vec_s *vec, const u8 *at);
bool wayc_raw_vec_pop(raw_vec_s *vec, u8 *out);
void wayc_raw_vec_deinit(raw_vec_s *vec);

template <typename T> struct vec_s {
  raw_vec_s raw;
};

#define WAYC_VEC_INIT(type) {WAYC_RAW_VEC_INIT(sizeof(type))}

template <typename T>
static inline void wayc_vec_push(vec_s<T> *vec, const T *at) {
  wayc_raw_vec_push(&vec->raw, (u8 *)at);
}

template <typename T> static inline bool wayc_vec_pop(vec_s<T> *vec, T *out) {
  return wayc_raw_vec_pop(&vec->raw, (u8 *)out);
}

template <typename T> static inline void wayc_vec_deinit(vec_s<T> *vec) {
  wayc_raw_vec_deinit(&vec->raw);
}