aboutsummaryrefslogtreecommitdiff
path: root/src/vec/ft_vecswallow.c
blob: 614022dcf0f93d689934b3c32a0066c6d9e164f0 (plain)
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
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_vecswallow.c                                    :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: charles <charles.cabergs@gmail.com>        +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/07/15 17:17:00 by charles           #+#    #+#             */
/*   Updated: 2020/07/15 18:30:37 by charles          ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "libft_vec.h"

/*
** \brief            Insert all element of a vector in an other vector
**                   and free the swallowed vector
** \param vec        Vector where the element will be inserted
** \param index      Index of the insertion
** \param swallowed  Vector to swallow
** \return           Destination vector or NULL on error
*/

t_ftvec	*ft_vecswallow_at(t_ftvec *vec, size_t index, t_ftvec *swallowed)
{
	size_t	i;

	if (ft_vecreserve(vec, vec->size + swallowed->size) == NULL)
		return (NULL);
	i = -1;
	while (++i < swallowed->size)
		ft_vecinsert(vec, index, swallowed->data[i]);
	ft_vecdestroy(swallowed, NULL);
	return (vec);
}