-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvector.h
47 lines (32 loc) · 959 Bytes
/
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
#ifndef __H_CEEF6E83FC3C441784ECEC6539B91AEB__
#define __H_CEEF6E83FC3C441784ECEC6539B91AEB__
#include <stdlib.h>
enum {
VECE_OK = 0,
VECE_NULL_POINTER,
VECE_OUT_OF_MEMORY,
VECE_OUT_OF_BOUNDS
};
struct vector {
size_t count;
size_t max;
void **mem;
};
inline static size_t vector_capacity(const struct vector *vec)
{
return vec ? vec->max : 0;
}
inline static size_t vector_count(const struct vector *vec)
{
return vec ? vec->count : 0;
}
int vector_add(struct vector *vec, void *item);
int vector_apply(struct vector *vec, void (*func)(void *));
int vector_delete(struct vector *vec, size_t index, void **item);
int vector_free(struct vector *vec);
int vector_get(struct vector *vec, size_t index, void **item);
int vector_init(struct vector *vec);
int vector_reserve(struct vector *vec, size_t size);
int vector_set(struct vector *vec, size_t index, void *item);
int vector_swap(struct vector *vec, size_t idx1, size_t idx2);
#endif