]>
Commit | Line | Data |
---|---|---|
74971473 JG |
1 | /* |
2 | * This file is part of the PCEPlib, a PCEP protocol library. | |
3 | * | |
4 | * Copyright (C) 2020 Volta Networks https://voltanet.io/ | |
5 | * | |
6 | * This library is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU Lesser General Public | |
8 | * License as published by the Free Software Foundation; either | |
9 | * version 2 of the License, or (at your option) any later version. | |
10 | * | |
11 | * This library is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * Lesser General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | |
18 | * | |
19 | * Author : Brady Johnson <brady@voltanet.io> | |
20 | * | |
21 | */ | |
22 | ||
23 | ||
24 | #ifndef PCEP_UTILS_INCLUDE_PCEP_UTILS_DOUBLE_LINKED_LIST_H_ | |
25 | #define PCEP_UTILS_INCLUDE_PCEP_UTILS_DOUBLE_LINKED_LIST_H_ | |
26 | ||
27 | typedef struct double_linked_list_node_ { | |
28 | struct double_linked_list_node_ *prev_node; | |
29 | struct double_linked_list_node_ *next_node; | |
30 | void *data; | |
31 | ||
32 | } double_linked_list_node; | |
33 | ||
34 | ||
35 | typedef struct double_linked_list_ { | |
36 | double_linked_list_node *head; | |
37 | double_linked_list_node *tail; | |
38 | unsigned int num_entries; | |
39 | ||
40 | } double_linked_list; | |
41 | ||
42 | ||
43 | /* Initialize a double linked list */ | |
44 | double_linked_list *dll_initialize(void); | |
45 | ||
46 | /* Destroy a double linked list, by freeing the handle and nodes, | |
47 | * user data will not be freed, and may be leaked if not handled | |
48 | * externally. */ | |
49 | void dll_destroy(double_linked_list *handle); | |
50 | /* Destroy a double linked list, by freeing the handle and nodes, | |
51 | * and the user data. */ | |
52 | void dll_destroy_with_data(double_linked_list *handle); | |
53 | void dll_destroy_with_data_memtype(double_linked_list *handle, | |
54 | void *data_memory_type); | |
55 | ||
56 | /* Creates a node and adds it as the first item in the list */ | |
57 | double_linked_list_node *dll_prepend(double_linked_list *handle, void *data); | |
58 | ||
59 | /* Creates a node and adds it as the last item in the list */ | |
60 | double_linked_list_node *dll_append(double_linked_list *handle, void *data); | |
61 | ||
62 | /* Delete the first node in the list, and return the data */ | |
63 | void *dll_delete_first_node(double_linked_list *handle); | |
64 | ||
65 | /* Delete the last node in the list, and return the data */ | |
66 | void *dll_delete_last_node(double_linked_list *handle); | |
67 | ||
68 | /* Delete the designated node in the list, and return the data */ | |
69 | void *dll_delete_node(double_linked_list *handle, | |
70 | double_linked_list_node *node); | |
71 | ||
72 | #endif /* PCEP_UTILS_INCLUDE_PCEP_UTILS_DOUBLE_LINKED_LIST_H_ */ |