1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "hks_double_list.h" 17 18 #ifndef NULL 19 #define NULL ((void *)0) 20 #endif 21 InitializeDoubleList(struct DoubleList * node)22void InitializeDoubleList(struct DoubleList *node) 23 { 24 if (node == NULL) { 25 return; 26 } 27 28 node->prev = node; 29 node->next = node; 30 } 31 AddNodeAfterDoubleListHead(struct DoubleList * head,struct DoubleList * node)32void AddNodeAfterDoubleListHead(struct DoubleList *head, struct DoubleList *node) 33 { 34 if ((head == NULL) || (node == NULL)) { 35 return; 36 } 37 38 if (head->next == NULL) { 39 head->next = head; 40 } 41 42 head->next->prev = node; 43 node->next = head->next; 44 node->prev = head; 45 head->next = node; 46 } 47 AddNodeAtDoubleListTail(struct DoubleList * head,struct DoubleList * node)48void AddNodeAtDoubleListTail(struct DoubleList *head, struct DoubleList *node) 49 { 50 if ((head == NULL) || (node == NULL)) { 51 return; 52 } 53 54 if (head->prev == NULL) { 55 head->prev = head; 56 } 57 58 head->prev->next = node; 59 node->next = head; 60 node->prev = head->prev; 61 head->prev = node; 62 } 63 RemoveDoubleListNode(struct DoubleList * node)64void RemoveDoubleListNode(struct DoubleList *node) 65 { 66 if (node == NULL) { 67 return; 68 } 69 70 if (node->next != NULL) { 71 node->next->prev = node->prev; 72 } 73 74 if (node->prev != NULL) { 75 node->prev->next = node->next; 76 } 77 78 node->prev = NULL; 79 node->next = NULL; 80 } 81 82