-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv_split.c
More file actions
37 lines (32 loc) · 1.57 KB
/
v_split.c
File metadata and controls
37 lines (32 loc) · 1.57 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* v_split.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: glegendr <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/12/18 22:40:22 by glegendr #+# #+# */
/* Updated: 2019/05/28 16:51:10 by glegendr ### ########.fr */
/* */
/* ************************************************************************** */
#include "vector.h"
t_vec v_split(t_vec *vec, int index)
{
t_vec vec2;
vec2 = v_new(vec->private_elem_size);
v_append_raw(&vec2, vec->private_content, index + 1);
v_memcpy(vec->private_content, v_get(vec, index + 1),
(vec->private_elem_nb - (index + 1)) * vec->private_elem_size);
vec->private_elem_nb -= index + 1;
return (vec2);
}
void *v_split_raw(t_vec *vec, int index)
{
void *ret;
ret = (void *)malloc(vec->private_elem_size * (index + 1));
v_memcpy(ret, vec->private_content, (index + 1) * vec->private_elem_size);
v_memcpy(vec->private_content, v_get(vec, index + 1),
(vec->private_elem_nb - (index + 1)) * vec->private_elem_size);
vec->private_elem_nb -= index + 1;
return (ret);
}