data_structures
array_copy.c
Go to the documentation of this file.
1 /* ************************************************************************** */
3 /* */
4 /* ::: :::::::: */
5 /* array_copy.c :+: :+: :+: */
6 /* +:+ +:+ +:+ */
7 /* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8 /* +#+#+#+#+#+ +#+ */
9 /* Created: 2020/07/22 00:23:30 by unite #+# #+# */
10 /* Updated: 2020/09/07 19:53:45 by unite ### ########.fr */
11 /* */
12 /* ************************************************************************** */
13 
14 #include "array.h"
15 
16 t_array *array_copy(const t_array *array)
17 {
18  t_array *copy;
19  size_t i;
20 
21  copy = array_zeros(array->type, array->size);
22  i = 0;
23  while (i < array->size)
24  {
25  array_set(copy, i, array_get(array, i));
26  i++;
27  }
28  copy->capacity = array->capacity;
29  copy->size = array->size;
30  return (copy);
31 }
array_get
void * array_get(const t_array *array, size_t index)
Returns the item at the specified position in this list.
Definition: array_get.c:16
array.h
array_copy
t_array * array_copy(const t_array *array)
Copies the array and all it contents.
Definition: array_copy.c:16
s_array::type
const t_type * type
The type of items in this array.
Definition: array.h:52
array_zeros
t_array * array_zeros(const t_type *type, size_t size)
Initializes a new array of the specified size, filled with zeros.
Definition: array_zeros.c:16
s_array
A resizable array.
Definition: array.h:47
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_set
void array_set(t_array *array, size_t index, const void *content)
Replaces the element at the specified position in this array with a copy of the specified element.
Definition: array_set.c:16