-
Notifications
You must be signed in to change notification settings - Fork 1
/
c_vector.c
52 lines (48 loc) · 1.86 KB
/
c_vector.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* c_vector.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aaubin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/02/12 22:11:51 by aaubin #+# #+# */
/* Updated: 2014/02/15 02:06:53 by aleger ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "c_vector.h"
static void init_pointers(t_vector **self)
{
(*self)->pop = &vector_pop;
(*self)->push = &vector_push;
(*self)->free = c_vector_free;
(*self)->each = c_vector_each;
(*self)->map = c_vector_map;
(*self)->remove = c_vector_remove;
(*self)->v_capacity = &vector_capacity;
(*self)->is_empty = &vector_is_empty;
(*self)->at = &vector_at;
(*self)->size = &vector_size;
(*self)->front = &vector_front;
(*self)->back = &vector_back;
(*self)->swap = &vector_swap;
(*self)->data = &vector_data;
(*self)->push_front = &vector_push_front;
(*self)->pop_front = &vector_pop_front;
}
t_vector *new_vector(size_t elt_size, void (*_delete)(void *))
{
t_vector *v;
v = (t_vector *)malloc(sizeof(t_vector));
if (v)
{
v->count = 0;
v->cursor = 0;
v->capacity = VECTOR_INIT_SIZE;
v->content = vector_memalloc(elt_size * v->capacity);
v->elt_size = elt_size;
init_pointers(&v);
v->delete_function = _delete != NULL ? _delete : NULL;
}
return (v);
}