-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvector.h
53 lines (43 loc) · 1.31 KB
/
vector.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
49
50
51
52
53
//
// Created by Thilo on 1/13/2017.
//
#ifndef VECTOR_H
#define VECTOR_H
#include <stddef.h>
#ifndef RSIZE_MAX
typedef size_t rsize_t;
#endif //RSIZE_MAX
#if __cplusplus
extern "C" {
#endif
#define INIT_VECTOR(type) initVector(sizeof(type));
typedef enum {
VEC_OK = 0,
VEC_OUT_OF_BOUNDS = -1
} VectorError;
typedef struct {
void* data;
size_t size;
size_t capacity;
size_t elemSize;
} Vector;
Vector initVector(size_t elemSize);
VectorError vectorAdd(Vector* vec, const void* elem);
VectorError vectorAddArray(Vector* vec, const void* elems, size_t length);
void* vectorGet(Vector* vec, rsize_t index);
void vectorClear(Vector* vec);
VectorError vectorShrinkToFit(Vector* vector);
VectorError vectorShrinkToFitExactly(Vector* vector);
VectorError vectorReserve(Vector* vec, size_t capacity);
VectorError vectorSwap(Vector* vec, rsize_t index1, rsize_t index2);
VectorError vectorInsert(Vector* vec, rsize_t index, const void* elem);
VectorError vectorRemoveFirst(Vector* vector);
VectorError vectorRemoveLast(Vector* vec);
VectorError vectorRemoveAt(Vector* vec, rsize_t index);
VectorError vectorRemoveRange(Vector* vec, rsize_t index, size_t end);
VectorError vectorInsertArray(Vector* vec, rsize_t index, const void* elems, size_t length);
void vectorDestroy(Vector* vec);
#if __cplusplus
}
#endif
#endif // VECTOR_H