]>
Commit | Line | Data |
---|---|---|
4e0938ef | 1 | /* |
bf95c10a | 2 | * Copyright (C) 1996-2022 The Squid Software Foundation and contributors |
4e0938ef AJ |
3 | * |
4 | * Squid software is distributed under GPLv2+ license and includes | |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
7 | */ | |
8 | ||
25f98340 | 9 | // XXX: This file is made of large pieces of src/tools.cc |
0d9a5f13 | 10 | // with only a few minor modifications. TODO: redesign or delete. |
11 | ||
582c2af2 FC |
12 | #include "squid.h" |
13 | #include "dlink.h" | |
4c50505b | 14 | |
f5691f9c | 15 | void |
af6a12ee AJ |
16 | dlinkAdd(void *data, dlink_node * m, dlink_list * list) |
17 | { | |
f5691f9c | 18 | m->data = data; |
aee3523a | 19 | m->prev = nullptr; |
f5691f9c | 20 | m->next = list->head; |
21 | ||
22 | if (list->head) | |
23 | list->head->prev = m; | |
24 | ||
25 | list->head = m; | |
26 | ||
aee3523a | 27 | if (list->tail == nullptr) |
f5691f9c | 28 | list->tail = m; |
29 | } | |
30 | ||
31 | void | |
af6a12ee AJ |
32 | dlinkAddAfter(void *data, dlink_node * m, dlink_node * n, dlink_list * list) |
33 | { | |
f5691f9c | 34 | m->data = data; |
35 | m->prev = n; | |
36 | m->next = n->next; | |
37 | ||
38 | if (n->next) | |
39 | n->next->prev = m; | |
40 | else { | |
41 | assert(list->tail == n); | |
42 | list->tail = m; | |
43 | } | |
44 | ||
45 | n->next = m; | |
46 | } | |
47 | ||
48 | void | |
af6a12ee AJ |
49 | dlinkAddTail(void *data, dlink_node * m, dlink_list * list) |
50 | { | |
f5691f9c | 51 | m->data = data; |
aee3523a | 52 | m->next = nullptr; |
f5691f9c | 53 | m->prev = list->tail; |
54 | ||
55 | if (list->tail) | |
56 | list->tail->next = m; | |
57 | ||
58 | list->tail = m; | |
59 | ||
aee3523a | 60 | if (list->head == nullptr) |
f5691f9c | 61 | list->head = m; |
62 | } | |
63 | ||
64 | void | |
af6a12ee AJ |
65 | dlinkDelete(dlink_node * m, dlink_list * list) |
66 | { | |
f5691f9c | 67 | if (m->next) |
68 | m->next->prev = m->prev; | |
69 | ||
70 | if (m->prev) | |
71 | m->prev->next = m->next; | |
72 | ||
73 | if (m == list->head) | |
74 | list->head = m->next; | |
75 | ||
76 | if (m == list->tail) | |
77 | list->tail = m->prev; | |
78 | ||
aee3523a | 79 | m->next = m->prev = nullptr; |
f5691f9c | 80 | } |
f53969cc | 81 |