-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdyn_array.h
48 lines (36 loc) · 1.21 KB
/
dyn_array.h
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
39
40
41
42
43
44
45
46
47
48
// This file implements a simple dynamic array system for an arbitrary data type DTYPE
// You must #define the following values before including this file:
// NAME: this is the name of the array type, used as the struct name and in all function names
// DTYPE: the array will be of this data type
// C_STRING_MODE: if defined, run free() on every element of the array before free()ing the
// DYPE *d object. Use strcmp rather than explicit comparision for some functions.
//#ifndef DYN_ARRAY_H
//#define DYN_ARRAY_H
#define CONCAT(a, b) CONCAT_(a, b)
#define CONCAT_(a, b) a ## b
//#ifndef CONCAT(DYN_ARRAY_H_, NAME)
//#define CONCAT(DYN_ARRAY_H_, NAME)
#include <stddef.h>
typedef struct {
DTYPE *d;
size_t allocated;
size_t used;
} NAME;
void
CONCAT(init, NAME)(NAME* new_arr);
void
CONCAT(dealloc, NAME)(NAME* arr);
void
CONCAT(_grow, NAME)(NAME* arr);
void
CONCAT(push, NAME)(NAME* arr, DTYPE new_element);
int
CONCAT(contains, NAME)(NAME* arr, DTYPE search, size_t *idx_ret);
void
CONCAT(truncate, NAME)(NAME* arr, size_t idx);
void
CONCAT(removeIdx, NAME)(NAME* arr, size_t idx);
void
CONCAT(removeVals, NAME)(NAME* arr, DTYPE element);
//#endif // DYN_ARRAY_H
//#endif // CONCAT(DYN_ARRAY_H_, NAME)