~nloomans/ft_select

ref: a4ef762331941c5e33670f7bf81eb964fb761edb ft_select/src/list2.c -rw-r--r-- 1.6 KiB
a4ef7623Noah Loomans fix build on linux 2 years ago
                                                                                
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
56
/* ************************************************************************** */
/*                                                                            */
/*                                                        ::::::::            */
/*   ft_select                                          :+:    :+:            */
/*                                                     +:+                    */
/*   Author: Noah Loomans                             +#+                     */
/*           <nloomans@student.codam.nl>             +#+                      */
/*                                                  #+#    #+#                */
/*   License: GPLv3                                ########   odam.nl         */
/*                                                                            */
/* ************************************************************************** */

#include <libft.h>
#include "list2.h"

void	list2_insert(
			t_list2_meta *meta,
			t_list2_conn *prev,
			t_list2_conn *new)
{
	new->prev = prev;
	if (new->prev)
	{
		new->next = new->prev->next;
		new->prev->next = new;
		if (new->next != NULL)
			new->next->prev = new;
		else
			meta->last = new;
	}
	else
	{
		new->next = meta->first;
		if (new->next)
			new->next->prev = new;
		meta->first = new;
		if (meta->last == NULL)
			meta->last = new;
	}
	meta->len++;
}

void	list2_unlink(
			t_list2_meta *meta,
			t_list2_conn *conn)
{
	if (meta->first == conn)
		meta->first = conn->next;
	if (meta->last == conn)
		meta->last = conn->prev;
	if (conn->prev)
		conn->prev->next = conn->next;
	if (conn->next)
		conn->next->prev = conn->prev;
	meta->len--;
}