-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlist.h
More file actions
193 lines (171 loc) · 9.35 KB
/
list.h
File metadata and controls
193 lines (171 loc) · 9.35 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*
******************************************************************************
* *
* Copyright (C) 2014 Chen Yan *
* Licensed under the MIT license *
* *
* The MIT License (MIT) *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
* DEALINGS IN THE SOFTWARE. *
* *
******************************************************************************
*/
/**************************************************************************//**
* @file list.h
* @date 2014-07-22
* @author Chen Yan <leochenlinux@gmail.com>
* @brief Doubly linked list
* @par Copyright
* Copyright (C) Chen Yan 2014 -2016. All rights reserved.
*****************************************************************************/
#ifndef _LIST_H_
#define _LIST_H_
/* Includes ---------------------------------------------------------------- */
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
/* External Interfaces ----------------------------------------------------- */
/**************************************************************************//**
* @fn list_create
* @param None
* @return Handle of the created list or NULL if failed
* @brief Create a new empty list
*****************************************************************************/
void *list_create( void );
/**************************************************************************//**
* @fn list_node_alloc
* @param [in] uiSize - Expected size of user data field
* @return Pointer to the created node or NULL if failed
* @brief Create a new element node with specified size of user data field
*****************************************************************************/
void *list_node_alloc( uint32_t uiSize );
/**************************************************************************//**
* @fn list_node_free
* @param [in] pvNode - Pointer to a node
* @return None
* @brief Free the memory of the given node
*****************************************************************************/
void list_node_free( void *pvNode );
/**************************************************************************//**
* @fn list_node_size
* @param [in] pvNode - Pointer to a node.
* @return The size of user data field
* @brief Get the size of user data field within the given node
*****************************************************************************/
uint32_t list_node_size( void *pvNode );
/**************************************************************************//**
* @fn list_add_rear
* @param [in] pvListEntry - List handle
* @param [in] pvNode - Pointer to a node
* @return None
* @brief Add a node at the end of a list
*****************************************************************************/
void list_add_rear( void *pvListEntry, void *pvNode );
/**************************************************************************//**
* @fn list_add_front
* @param [in] pvListEntry - List handle
* @param [in] pvNode - Pointer to a node.
* @return None
* @brief Add a node at the beginning of a list.
*****************************************************************************/
void list_add_front( void *pvListEntry, void *pvNode );
/**************************************************************************//**
* @fn list_insert_before
* @param [in] pvNodeA - Pointer to a node.
* @param [in] pvNodeB - Pointer to the node to be inserted.
* @return None
* @brief Insert a node before another node.
*****************************************************************************/
void list_insert_before( void *pvNodeA, void *pvNodeB );
/**************************************************************************//**
* @fn ilst_insert_after
* @param [in] pvNodeA - Pointer to a node.
* @param [in] pvNodeB - Pointer to the node to be inserted.
* @return None
* @brief Insert a node after another node.
*****************************************************************************/
void ilst_insert_after( void *pvNodeA, void *pvNodeB );
/**************************************************************************//**
* @fn list_node_del
* @param [in] pvNode - Pointer to a node.
* @return None
* @brief Delete a node from list. Note the node will not be freed.
*****************************************************************************/
void list_node_del( void *pvNode );
/**************************************************************************//**
* @fn list_node_swap
* @param [in] pvNodeA - Pointer to a node.
* @param [in] pvNodeB - Pointer to another node.
* @return None
* @brief Swap two nodes
*****************************************************************************/
void list_node_swap( void *pvNodeA, void *pvNodeB );
/**************************************************************************//**
* @fn list_node_first
* @param [in] pvListEntry - List handle
* @return Pointer to the node or NULL if not founded
* @brief Get the node at the beginning of the specified list.
*****************************************************************************/
void *list_node_first( void *pvListEntry );
/**************************************************************************//**
* @fn list_node_last
* @param [in] pvListEntry - List handle
* @return Pointer to the node or NULL if not founded
* @brief Get the node at the end of the specified list.
*****************************************************************************/
void *list_node_last( void *pvListEntry );
/**************************************************************************//**
* @fn list_node_next
* @param [in] pvNode - Pointer to a node.
* @return Pointer to the the next node
* @brief Get next node or NULL if reach the end of list
*****************************************************************************/
void *list_node_next( void *pvNode );
/**************************************************************************//**
* @fn list_node_prev
* @param [in] pvNode - Pointer to a node.
* @return Pointer to the the previous node
* @brief Get next node or NULL if reach the beginning of list
*****************************************************************************/
void *list_node_prev( void *pvNode );
/**************************************************************************//**
* @fn list_length
* @param [in] pvListEntry - List handle
* @return The number of nodes in the list.
* @brief Get the number of nodes in a list.
*****************************************************************************/
uint32_t list_length( void *pvListEntry );
/**************************************************************************//**
* @fn list_flush
* @param [in] pvListEntry - List handle
* @return None
* @brief Flush a list. All nodes in list will be deleted and freed
*****************************************************************************/
void list_flush( void *pvListEntry );
/**************************************************************************//**
* @fn list_destroy
* @param [in] pvListEntry - List handle
* @return None
* @brief Free the list including all nodes in it.
*****************************************************************************/
void list_destroy( void *pvListEntry );
#endif /* _LIST_H_ */
/******************************************************************************
* End of File
*****************************************************************************/