data_structures
src
data_structures
array
array_remove.c
Go to the documentation of this file.
1
/* ************************************************************************** */
3
/* */
4
/* ::: :::::::: */
5
/* array_remove.c :+: :+: :+: */
6
/* +:+ +:+ +:+ */
7
/* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8
/* +#+#+#+#+#+ +#+ */
9
/* Created: 2020/07/18 23:34:25 by unite #+# #+# */
10
/* Updated: 2020/09/07 21:50:23 by unite ### ########.fr */
11
/* */
12
/* ************************************************************************** */
13
14
#include "
array.h
"
15
#include "
array_utils.h
"
16
17
void
array_remove
(
t_array
*array,
size_t
index)
18
{
19
if
(index >= array->
size
)
20
ds_exit_set
(EINVAL);
21
array->
type
->
del
(array->
arr
[index]);
22
while
(index < array->size - 1)
23
{
24
array->
arr
[index] = array->
arr
[index + 1];
25
index++;
26
}
27
array->
size
--;
28
if
(array->
size
<= array->
capacity
/ 4)
29
array_shrink(array);
30
}
array.h
s_array::type
const t_type * type
The type of items in this array.
Definition:
array.h:52
s_array::arr
void ** arr
The data.
Definition:
array.h:51
s_array
A resizable array.
Definition:
array.h:47
s_type::del
void(* del)(void *)
A function pointer used to free the memory taken by the data type.
Definition:
types.h:51
s_array::capacity
size_t capacity
The capacity of this array.
Definition:
array.h:50
s_array::size
size_t size
The number of items in this array.
Definition:
array.h:49
array_remove
void array_remove(t_array *array, size_t index)
Deletes the item at the specified index.
Definition:
array_remove.c:17
ds_exit_set
void ds_exit_set(int err)
Set errno to the specified value, print the error message, and exit the process.
Definition:
ds_exit_set.c:22
array_utils.h
Generated by
1.8.16