]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - VtoyTool/BabyISO/biso_list.c
1.1.07 release
[Ventoy.git] / VtoyTool / BabyISO / biso_list.c
1 /******************************************************************************
2 * biso_list.c
3 *
4 * Copyright (c) 2020, longpanda <admin@ventoy.net>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * 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 <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #include "biso.h"
22 #include "biso_list.h"
23 #include "biso_util.h"
24
25 VOID BISO_DLL_Init(OUT BISO_DLL_S *pstList)
26 {
27 pstList->stHead.pstNext = &(pstList->stHead);
28 pstList->stHead.pstPre = &(pstList->stHead);
29 pstList->pstTail = &(pstList->stHead);
30 pstList->uiCount = 0;
31 }
32
33 VOID BISO_DLL_AddTail
34 (
35 IN BISO_DLL_S *pstList,
36 IN BISO_DLL_NODE_S *pstNode
37 )
38 {
39 pstList->pstTail->pstNext = pstNode;
40 pstNode->pstNext = NULL;
41 pstNode->pstPre = pstList->pstTail;
42 pstList->pstTail = pstNode;
43 pstList->uiCount++;
44 }
45
46 VOID BISO_DLL_DelHead(IN BISO_DLL_S *pstList)
47 {
48 BISO_DLL_NODE_S *pstFirst = BISO_DLL_First(pstList);
49
50 if (NULL != pstFirst)
51 {
52 if (1 == BISO_DLL_Count(pstList)) /* 唯一节点 */
53 {
54 BISO_DLL_Init(pstList);
55 }
56 else
57 {
58 pstFirst->pstNext->pstPre = &(pstList->stHead);
59 pstList->stHead.pstNext = pstFirst->pstNext;
60 pstList->uiCount--;
61 }
62 }
63 }
64 VOID BISO_DLL_DelTail(IN BISO_DLL_S *pstList)
65 {
66 BISO_DLL_NODE_S *pstLast = BISO_DLL_Last(pstList);
67
68 if (NULL != pstLast)
69 {
70 if (1 == BISO_DLL_Count(pstList)) /* 唯一节点 */
71 {
72 BISO_DLL_Init(pstList);
73 }
74 else
75 {
76 pstLast->pstPre->pstNext = NULL;
77 pstList->pstTail = pstLast->pstPre;
78 pstList->uiCount--;
79 }
80 }
81 }
82
83 VOID BISO_DLL_Free(IN BISO_DLL_S *pstList)
84 {
85 BISO_DLL_NODE_S *pstFirst = BISO_DLL_First(pstList);
86
87 while (NULL != pstFirst)
88 {
89 /* 每次都摘掉头节点 */
90 BISO_DLL_DelHead(pstList);
91
92 /* 使用free释放节点 */
93 BISO_FREE(pstFirst);
94 pstFirst = BISO_DLL_First(pstList);
95 }
96 }
97
98