-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcvec.h
60 lines (41 loc) · 1023 Bytes
/
cvec.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
54
55
56
57
58
59
#ifdef __cplusplus
extern "C" {
#endif
#ifndef CVEC_H
#define CVEC_H
#include <stdlib.h>
#include <stddef.h>
#include <stdint.h>
#define CVEC_NEW(vec, type, capacity) cvec_init(&vec, sizeof(type), capacity)
typedef struct cvec
{
size_t size; // number of elements
size_t pcap; // + capacity
size_t ncap; // - capacity
size_t tcap; // total capacity
size_t tsz; // type size
void *aaddr; // alloced address
void *vaddr; // vector address
} cvec_t;
int
cvec_init(cvec_t *vec ,size_t type_size, size_t capacity);
void
cvec_destroy(cvec_t *vec , void (*iter)(void *));
int
cvec_push(cvec_t *vec, void *addr);
int
cvec_pop(cvec_t *vec, void *addr);
int
cvec_get(cvec_t *vec, void *addr, size_t index);
void *
cvec_ptr(cvec_t *vec, size_t index);
int
cvec_insert(cvec_t *vec, void *addr, size_t index);
int
cvec_erase(cvec_t *vec, size_t index, void (*destroy)(void *));
int
cvec_iter(cvec_t *vec, void *any, void (*f)(void *elemnet_addr, void *any));
#endif
#ifdef __cplusplus
}
#endif