-
Notifications
You must be signed in to change notification settings - Fork 311
/
Copy pathcstl_queue.c
255 lines (216 loc) · 6.27 KB
/
cstl_queue.c
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/*
* The implemention of queue.
* Copyright (C) 2008 - 2012 Wangbo
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author e-mail: activesys.wb@gmail.com
* activesys@sina.com.cn
*/
/** include section **/
#include <cstl/cqueue.h>
/** local constant declaration and local macro section **/
/** local data type declaration and local struct, union, enum section **/
/** local function prototype section **/
/** exported global variable definition section **/
/** local global variable definition section **/
/** exported function implementation section **/
/**
* Initialize an empty queue adaptor
*/
void queue_init(queue_t* pque_queue)
{
assert(pque_queue != NULL);
#ifdef CSTL_QUEUE_LIST_SEQUENCE
list_init(&pque_queue->_t_sequence);
#else
deque_init(&pque_queue->_t_sequence);
#endif
}
/**
* Initialize queue adaptor with exist queue adaptor.
*/
void queue_init_copy(queue_t* pque_dest, const queue_t* cpque_src)
{
assert(pque_dest != NULL);
assert(cpque_src != NULL);
#ifdef CSTL_QUEUE_LIST_SEQUENCE
list_init_copy(&pque_dest->_t_sequence, &cpque_src->_t_sequence);
#else
deque_init_copy(&pque_dest->_t_sequence, &cpque_src->_t_sequence);
#endif
}
/**
* Destroy queue adaptor.
*/
void queue_destroy(queue_t* pque_queue)
{
assert(pque_queue != NULL);
_queue_destroy_auxiliary(pque_queue);
free(pque_queue);
}
/**
* Assign queue element with an exist queue adaptor.
*/
void queue_assign(queue_t* pque_dest, const queue_t* cpque_src)
{
assert(pque_dest != NULL);
assert(cpque_src != NULL);
#ifdef CSTL_QUEUE_LIST_SEQUENCE
list_assign(&pque_dest->_t_sequence, &cpque_src->_t_sequence);
#else
deque_assign(&pque_dest->_t_sequence, &cpque_src->_t_sequence);
#endif
}
/**
* Tests if a queue is empty.
*/
bool_t queue_empty(const queue_t* cpque_queue)
{
assert(cpque_queue != NULL);
#ifdef CSTL_QUEUE_LIST_SEQUENCE
return list_empty(&cpque_queue->_t_sequence);
#else
return deque_empty(&cpque_queue->_t_sequence);
#endif
}
/**
* Return the number of elements in a queue.
*/
size_t queue_size(const queue_t* cpque_queue)
{
assert(cpque_queue != NULL);
#ifdef CSTL_QUEUE_LIST_SEQUENCE
return list_size(&cpque_queue->_t_sequence);
#else
return deque_size(&cpque_queue->_t_sequence);
#endif
}
/**
* Access queue front data.
*/
void* queue_front(const queue_t* cpque_queue)
{
assert(cpque_queue != NULL);
#ifdef CSTL_QUEUE_LIST_SEQUENCE
return list_front(&cpque_queue->_t_sequence);
#else
return deque_front(&cpque_queue->_t_sequence);
#endif
}
/**
* Access queue last data.
*/
void* queue_back(const queue_t* cpque_queue)
{
assert(cpque_queue != NULL);
#ifdef CSTL_QUEUE_LIST_SEQUENCE
return list_back(&cpque_queue->_t_sequence);
#else
return deque_back(&cpque_queue->_t_sequence);
#endif
}
/**
* Delete the element at the begin of queue.
*/
void queue_pop(queue_t* pque_queue)
{
assert(pque_queue != NULL);
#ifdef CSTL_QUEUE_LIST_SEQUENCE
list_pop_front(&pque_queue->_t_sequence);
#else
deque_pop_front(&pque_queue->_t_sequence);
#endif
}
/**
* Tests if the two queues are equal.
*/
bool_t queue_equal(const queue_t* cpque_first, const queue_t* cpque_second)
{
assert(cpque_first != NULL);
assert(cpque_second != NULL);
#ifdef CSTL_QUEUE_LIST_SEQUENCE
return list_equal(&cpque_first->_t_sequence, &cpque_second->_t_sequence);
#else
return deque_equal(&cpque_first->_t_sequence, &cpque_second->_t_sequence);
#endif
}
/**
* Test the two queues are unequal.
*/
bool_t queue_not_equal(const queue_t* cpque_first, const queue_t* cpque_second)
{
assert(cpque_first != NULL);
assert(cpque_second != NULL);
#ifdef CSTL_QUEUE_LIST_SEQUENCE
return list_not_equal(&cpque_first->_t_sequence, &cpque_second->_t_sequence);
#else
return deque_not_equal(&cpque_first->_t_sequence, &cpque_second->_t_sequence);
#endif
}
/**
* Test the first queue is less than the second queue.
*/
bool_t queue_less(const queue_t* cpque_first, const queue_t* cpque_second)
{
assert(cpque_first != NULL);
assert(cpque_second != NULL);
#ifdef CSTL_QUEUE_LIST_SEQUENCE
return list_less(&cpque_first->_t_sequence, &cpque_second->_t_sequence);
#else
return deque_less(&cpque_first->_t_sequence, &cpque_second->_t_sequence);
#endif
}
/**
* Test the first queue is less than or equal to the second queue.
*/
bool_t queue_less_equal(const queue_t* cpque_first, const queue_t* cpque_second)
{
assert(cpque_first != NULL);
assert(cpque_second != NULL);
#ifdef CSTL_QUEUE_LIST_SEQUENCE
return list_less_equal(&cpque_first->_t_sequence, &cpque_second->_t_sequence);
#else
return deque_less_equal(&cpque_first->_t_sequence, &cpque_second->_t_sequence);
#endif
}
/**
* Test the first queue is greater than the second queue.
*/
bool_t queue_greater(const queue_t* cpque_first, const queue_t* cpque_second)
{
assert(cpque_first != NULL);
assert(cpque_second != NULL);
#ifdef CSTL_QUEUE_LIST_SEQUENCE
return list_greater(&cpque_first->_t_sequence, &cpque_second->_t_sequence);
#else
return deque_greater(&cpque_first->_t_sequence, &cpque_second->_t_sequence);
#endif
}
/**
* Test the first queue is greater than or equal to the second queue.
*/
bool_t queue_greater_equal(const queue_t* cpque_first, const queue_t* cpque_second)
{
assert(cpque_first != NULL);
assert(cpque_second != NULL);
#ifdef CSTL_QUEUE_LIST_SEQUENCE
return list_greater_equal(&cpque_first->_t_sequence, &cpque_second->_t_sequence);
#else
return deque_greater_equal(&cpque_first->_t_sequence, &cpque_second->_t_sequence);
#endif
}
/** local function implementation section **/
/** eof **/