-
Notifications
You must be signed in to change notification settings - Fork 1
/
c_vector_remove.c
55 lines (50 loc) · 1.52 KB
/
c_vector_remove.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
53
54
55
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* c_vector_remove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aaubin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/02/13 18:40:23 by aaubin #+# #+# */
/* Updated: 2014/02/15 05:23:29 by aleger ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "c_vector.h"
void c_vector_free(t_vector *self)
{
size_t i;
i = 0;
if (self->delete_function != NULL)
{
while (i < self->count)
{
self->delete_function(VECTOR_INDEX(i));
i++;
}
}
self->count = 0;
self->capacity = 0;
free(self->content);
self->content = NULL;
}
int c_vector_remove(size_t i, t_vector *self)
{
int index;
index = (int)i;
if (i > 0)
{
if (!VECTOR_INBOUNDS(i))
return (0);
while (index < (int)(self->count - 1))
{
vector_memcpy(VECTOR_INDEX(index), VECTOR_INDEX(index + 1),
self->elt_size);
++index;
}
--(self->count);
return (1);
}
else
return (0);
}