-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlist.h
84 lines (63 loc) · 1.85 KB
/
list.h
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#ifndef LIST_H
#define LIST_H
/* ################################################################### */
/* Copyright 2022, Pierre Gentile ([email protected]) */
/* */
/* This Source Code Form is subject to the terms of the Mozilla Public */
/* License, v. 2.0. If a copy of the MPL was not distributed with this */
/* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
/* ################################################################### */
/* ******************************* */
/* Linked list specific structures */
/* ******************************* */
/* Linked list node structure */
/* """""""""""""""""""""""""" */
struct ll_node_s
{
void *data;
struct ll_node_s *next;
struct ll_node_s *prev;
};
typedef struct ll_node_s ll_node_t;
/* Linked List structure */
/* """"""""""""""""""""" */
struct ll_s
{
ll_node_t *head;
ll_node_t *tail;
size_t len;
};
typedef struct ll_s ll_t;
ll_t *
ll_new(void);
void
ll_init(ll_t *list);
ll_node_t *
ll_new_node(void);
void
ll_append(ll_t * const list, void * const data);
void
ll_prepend(ll_t * const list, void * const data);
void
ll_insert_before(ll_t * const list, ll_node_t *node, void * const data);
void
ll_insert_after(ll_t * const list, ll_node_t *node, void * const data);
ll_t *
ll_concat(ll_t *list1, ll_t *list2);
ll_t *
ll_merge(ll_t *list1, ll_t *list2, int merge_before);
void
ll_sort(ll_t *list,
int (*ll_comp)(const void *, const void *),
void (*ll_swap)(void **a, void **));
int
ll_delete(ll_t * const list, ll_node_t *node);
ll_node_t *
ll_find(ll_t * const list,
void const *data,
int (*cmpfunc)(void const *a, void const *b));
void
ll_free(ll_t * const list, void (*clean)(void *));
void
ll_destroy(ll_t *list, void (*clean)(void *));
#endif