0
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2 CircularQueue
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3 Copyright (C) 2002 Eric Wing
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5 This library is free software; you can redistribute it and/or
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6 modify it under the terms of the GNU Library General Public
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7 License as published by the Free Software Foundation; either
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
8 version 2 of the License, or (at your option) any later version.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
9
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
10 This library is distributed in the hope that it will be useful,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
13 Library General Public License for more details.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
14
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
15 You should have received a copy of the GNU Library General Public
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
16 License along with this library; if not, write to the Free
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
18 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
19
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
20
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
21 #ifndef C_CIRCULAR_QUEUE_H
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
22 #define C_CIRCULAR_QUEUE_H
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
23
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
24 /* Set up for C function definitions, even when using C++ */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
25 #ifdef __cplusplus
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
26 extern "C" {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
27 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
28
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
29 /**
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
30 * @file
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
31 * This is a C-based Circular queue class.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
32 * This class provides very simple circular queue functionality,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
33 * with an API similar to the C++ STL queue class.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
34 * Currently, a queue cannot be resized.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
35 * Because C doesn't do templates and I really don't want
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
36 * to write my own polymorphism, you must select the proper queue
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
37 * for your data types.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
38 * I currently provide an unisigned int version
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
39 * and a void* version. The void* version will let you use any type,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
40 * but remember that you are responsible for casting and maintaining
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
41 * your own type safety. I have found the unsigned int version to be
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
42 * very useful because if you have a map somewhere that associates
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
43 * unique identifier numbers to data (e.g. OpenGL displaylists/textures),
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
44 * then you can just deal with the id numbers and don't have to deal with
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
45 * the casting and typesafety issues. I recommend you don't overlook the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
46 * usefulness of this version.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
47 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
48 * @warning Do not mix the CircularQueues created from the different versions.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
49 * They are incompatible. Use only CircularQueueUnsignedInt objects with
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
50 * CircularQueueUnsignedInt_* functions, etc.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
51 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
52 * Example Usage:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
53 * @code
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
54 * CircularQueueUnsignedInt* myqueue;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
55 * unsigned int ret_val;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
56 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
57 * myqueue = CircularQueueUnsignedInt_CreateQueue(3);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
58 * if(NULL == myqueue)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
59 * {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
60 * fprintf(stderr, "Error, could not create queue\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
61 * return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
62 * }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
63 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
64 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
65 * ret_val = CircularQueueUnsignedInt_PushBack(myqueue, 1);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
66 * ret_val = CircularQueueUnsignedInt_PushBack(myqueue, 2);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
67 * ret_val = CircularQueueUnsignedInt_PushBack(myqueue, 3);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
68 * if(0 == ret_val)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
69 * {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
70 * fprintf(stderr, "Error, Could not pushback\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
71 * exit(1);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
72 * }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
73 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
74 * ret_val = CircularQueueUnsignedInt_PopBack(myqueue);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
75 * if(0 == ret_val)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
76 * {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
77 * fprintf(stderr, "Error, Could not popback\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
78 * exit(2);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
79 * }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
80 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
81 * fprintf(stderr, "Testing queue, should have 1,2\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
82 * CircularQueueUnsignedInt_Print(myqueue);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
83 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
84 * ret_val = CircularQueueUnsignedInt_PushFront(myqueue, 4);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
85 * if(0 == ret_val)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
86 * {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
87 * fprintf(stderr, "Error, Could not pushfront\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
88 * exit(1);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
89 * }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
90 * fprintf(stderr, "Testing queue, should have 4,1,2\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
91 * CircularQueueUnsignedInt_Print(myqueue);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
92 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
93 * @endcode
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
94 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
95
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
96 /**
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
97 * This is the essentially the CircularQueue object.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
98 * This contains all the data associated with a CircularQueue instance.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
99 * This version is for unsigned int data types. In the future, I suppose
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
100 * I could add a void* data type at the very least and maybe some
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
101 * other data types.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
102 * This should be considered an opaque data type.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
103 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
104 typedef struct
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
105 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
106 unsigned int maxSize; /**< Max size of the queue. */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
107 unsigned int currentSize; /**< Current number of entries in the queue. */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
108 unsigned int headIndex; /**< The index of where the current head is. */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
109 unsigned int tailIndex; /**< The index of where the current tail is. */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
110 unsigned int* internalQueue; /**< The array representing the queue. */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
111 } CircularQueueUnsignedInt;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
112
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
113 /**
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
114 * This creates a new CircularQueue (for unsigned int) instance.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
115 * This will create a new circular queue instance which holds
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
116 * unsigned int's in its queue.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
117 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
118 * @note This implementation does not allow a circular queue to be resized.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
119 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
120 * @param max_size This specifies the maximum number of elements the circular
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
121 * can hold.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
122 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
123 * @return Returns a pointer to a CircularQueue which is the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
124 * instance variable (if successful) or NULL on failure.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
125 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
126 * @see CircularQueueUnsignedInt_FreeQueue
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
127 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
128 CircularQueueUnsignedInt* CircularQueueUnsignedInt_CreateQueue(unsigned int max_size);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
129
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
130 /**
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
131 * This destroys a CircularQueue instance.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
132 * This will destroy the memory associated with the circular queue instance.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
133 * Whenever you create a CircularQueue instance, you should always to
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
134 * remember to balance it with a FreeQueue.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
135 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
136 * @param queue The pointer to the CircularQueue instance.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
137 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
138 * @see CircularQueueUnsignedInt_CreateQueue
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
139 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
140 void CircularQueueUnsignedInt_FreeQueue(CircularQueueUnsignedInt* queue);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
141
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
142 /**
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
143 * This pushes a new value into the back of the queue.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
144 * If the queue is full, the function will fail and return 0.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
145 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
146 * @param queue The pointer to the CircularQueue instance.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
147 * @param value The value you want to push into the queue.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
148 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
149 * @return Returns 1 on success, or 0 on failure.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
150 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
151 unsigned int CircularQueueUnsignedInt_PushBack(CircularQueueUnsignedInt* queue, unsigned int value);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
152
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
153 /**
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
154 * This pushes a new value into the front of the queue.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
155 * If the queue is full, the function will fail and return 0.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
156 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
157 * @param queue The pointer to the CircularQueue instance.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
158 * @param value The value you want to push into the queue.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
159 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
160 * @return Returns 1 on success, or 0 on failure.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
161 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
162 unsigned int CircularQueueUnsignedInt_PushFront(CircularQueueUnsignedInt* queue, unsigned int value);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
163
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
164 /**
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
165 * This removes the value at the front of the queue.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
166 * If the queue is empty, the function will return 0.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
167 * Note that this function does not return the value popped, but
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
168 * an error flag. If you need the value, you must call Front()
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
169 * to retrieve the value before popping it.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
170 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
171 * @param queue The pointer to the CircularQueue instance.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
172 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
173 * @return Returns 1 on success, or 0 on failure.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
174 * @see CircularQueueUnsignedInt_Front
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
175 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
176 unsigned int CircularQueueUnsignedInt_PopFront(CircularQueueUnsignedInt* queue);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
177
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
178 /**
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
179 * This removes the value at the back of the queue.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
180 * If the queue is empty, the function will return 0.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
181 * Note that this function does not return the value popped, but
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
182 * an error flag. If you need the value, you must call Back()
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
183 * to retrieve the value before popping it.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
184 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
185 * @param queue The pointer to the CircularQueue instance.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
186 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
187 * @return Returns 1 on success, or 0 on failure.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
188 * @see CircularQueueUnsignedInt_Back
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
189 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
190 unsigned int CircularQueueUnsignedInt_PopBack(CircularQueueUnsignedInt* queue);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
191
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
192 /**
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
193 * This gets the value at the front of the queue.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
194 * If the queue is empty, the value returned will be 0.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
195 * Because this 0 return value is ambiguous because it could also could
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
196 * be a legitimate value in the queue, if you need more robust error
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
197 * checking for if the queue is empty, you should get the size of the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
198 * queue using the Size() function.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
199 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
200 * @param queue The pointer to the CircularQueue instance.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
201 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
202 * @return Returns the value stored at the queue or 0 if the queue is empty
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
203 * (or if there is an error).
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
204 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
205 * @see CircularQueueUnsignedInt_Size
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
206 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
207 unsigned int CircularQueueUnsignedInt_Front(CircularQueueUnsignedInt* queue);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
208
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
209 /**
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
210 * This gets the value at the back of the queue.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
211 * If the queue is empty, the value returned will be 0.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
212 * Because this 0 return value is ambiguous because it could also could
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
213 * be a legitimate value in the queue, if you need more robust error
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
214 * checking for if the queue is empty, you should get the size of the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
215 * queue using the Size() function.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
216 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
217 * @param queue The pointer to the CircularQueue instance.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
218 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
219 * @return Returns the value stored at the queue or 0 if the queue is empty
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
220 * (or 0 if there is an error).
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
221 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
222 * @see CircularQueueUnsignedInt_Size
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
223 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
224 unsigned int CircularQueueUnsignedInt_Back(CircularQueueUnsignedInt* queue);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
225
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
226 /**
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
227 * This gets the current number of entries that are in the queue.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
228 * This is number is not to be confused with the MaxSize.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
229 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
230 * @param queue The pointer to the CircularQueue instance.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
231 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
232 * @return Returns the number of entries currently in queue, or 0 if
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
233 * there is an error.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
234 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
235 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
236 unsigned int CircularQueueUnsignedInt_Size(CircularQueueUnsignedInt* queue);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
237
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
238 /**
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
239 * This gets the maximum number of entries that are allowed in the queue at
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
240 * a given time.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
241 * This is the number that you used in the CreateQueue function.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
242 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
243 * @param queue The pointer to the CircularQueue instance.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
244 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
245 * @return Returns the maximum number of entries allowed in the queue.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
246 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
247 unsigned int CircularQueueUnsignedInt_MaxSize(CircularQueueUnsignedInt* queue);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
248 /**
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
249 * This empties the entire queue.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
250 * This will remove all entries that are in the queue.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
251 * This does not destroy any memory. Use FreeQueue() to actually destroy
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
252 * the queue.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
253 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
254 * @param queue The pointer to the CircularQueue instance.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
255 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
256 void CircularQueueUnsignedInt_Clear(CircularQueueUnsignedInt* queue);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
257
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
258 /**
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
259 * This is a debugging function that will print all the elements in the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
260 * queue to stderr.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
261 * This function is provided as convenience, but should not be considered
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
262 * as part of the standard API. Treat this function as deprecated
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
263 * as it's implementation may change or be removed entirely.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
264 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
265 * @param queue The pointer to the CircularQueue instance.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
266 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
267 void CircularQueueUnsignedInt_Print(CircularQueueUnsignedInt* queue);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
268
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
269
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
270 /**
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
271 * This is the essentially the CircularQueue object.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
272 * This contains all the data associated with a CircularQueue instance.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
273 * This version is for unsigned int data types. In the future, I suppose
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
274 * I could add a void* data type at the very least and maybe some
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
275 * other data types.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
276 * This should be considered an opaque data type.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
277 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
278 typedef struct
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
279 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
280 unsigned int maxSize; /**< Max size of the queue. */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
281 unsigned int currentSize; /**< Current number of entries in the queue. */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
282 unsigned int headIndex; /**< The index of where the current head is. */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
283 unsigned int tailIndex; /**< The index of where the current tail is. */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
284 void** internalQueue; /**< The array representing the queue. */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
285 } CircularQueueVoid;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
286
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
287 /**
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
288 * This creates a new CircularQueue (for void* ) instance.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
289 * This will create a new circular queue instance which holds
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
290 * unsigned int's in its queue.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
291 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
292 * @note This implementation does not allow a circular queue to be resized.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
293 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
294 * @param max_size This specifies the maximum number of elements the circular
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
295 * can hold.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
296 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
297 * @return Returns a pointer to a CircularQueue which is the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
298 * instance variable (if successful) or NULL on failure.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
299 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
300 * @see CircularQueueVoid_FreeQueue
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
301 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
302 CircularQueueVoid* CircularQueueVoid_CreateQueue(unsigned int max_size);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
303
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
304 /**
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
305 * This destroys a CircularQueue instance.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
306 * This will destroy the memory associated with the circular queue instance.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
307 * Whenever you create a CircularQueue instance, you should always to
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
308 * remember to balance it with a FreeQueue.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
309 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
310 * @param queue The pointer to the CircularQueue instance.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
311 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
312 * @see CircularQueueVoid_CreateQueue
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
313 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
314 void CircularQueueVoid_FreeQueue(CircularQueueVoid* queue);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
315
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
316 /**
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
317 * This pushes a new value into the back of the queue.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
318 * If the queue is full, the function will fail and return 0.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
319 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
320 * @param queue The pointer to the CircularQueue instance.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
321 * @param value The value you want to push into the queue.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
322 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
323 * @return Returns 1 on success, or 0 on failure.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
324 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
325 unsigned int CircularQueueVoid_PushBack(CircularQueueVoid* queue, void* value);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
326
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
327 /**
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
328 * This pushes a new value into the front of the queue.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
329 * If the queue is full, the function will fail and return 0.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
330 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
331 * @param queue The pointer to the CircularQueue instance.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
332 * @param value The value you want to push into the queue.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
333 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
334 * @return Returns 1 on success, or 0 on failure.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
335 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
336 unsigned int CircularQueueVoid_PushFront(CircularQueueVoid* queue, void* value);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
337
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
338 /**
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
339 * This removes the value at the front of the queue.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
340 * If the queue is empty, the function will return 0.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
341 * Note that this function does not return the value popped, but
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
342 * an error flag. If you need the value, you must call Front()
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
343 * to retrieve the value before popping it.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
344 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
345 * @param queue The pointer to the CircularQueue instance.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
346 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
347 * @return Returns 1 on success, or 0 on failure.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
348 * @see CircularQueueVoid_Front
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
349 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
350 unsigned int CircularQueueVoid_PopFront(CircularQueueVoid* queue);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
351
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
352 /**
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
353 * This removes the value at the back of the queue.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
354 * If the queue is empty, the function will return 0.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
355 * Note that this function does not return the value popped, but
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
356 * an error flag. If you need the value, you must call Back()
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
357 * to retrieve the value before popping it.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
358 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
359 * @param queue The pointer to the CircularQueue instance.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
360 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
361 * @return Returns 1 on success, or 0 on failure.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
362 * @see CircularQueueVoid_Back
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
363 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
364 unsigned int CircularQueueVoid_PopBack(CircularQueueVoid* queue);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
365
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
366 /**
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
367 * This gets the value at the front of the queue.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
368 * If the queue is empty, the value returned will be 0.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
369 * Because this 0 return value is ambiguous because it could also could
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
370 * be a legitimate value in the queue, if you need more robust error
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
371 * checking for if the queue is empty, you should get the size of the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
372 * queue using the Size() function.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
373 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
374 * @param queue The pointer to the CircularQueue instance.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
375 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
376 * @return Returns the value stored at the queue or 0 if the queue is empty
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
377 * (or if there is an error).
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
378 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
379 * @see CircularQueueVoid_Size
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
380 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
381 void* CircularQueueVoid_Front(CircularQueueVoid* queue);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
382
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
383 /**
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
384 * This gets the value at the back of the queue.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
385 * If the queue is empty, the value returned will be 0.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
386 * Because this 0 return value is ambiguous because it could also could
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
387 * be a legitimate value in the queue, if you need more robust error
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
388 * checking for if the queue is empty, you should get the size of the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
389 * queue using the Size() function.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
390 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
391 * @param queue The pointer to the CircularQueue instance.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
392 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
393 * @return Returns the value stored at the queue or 0 if the queue is empty
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
394 * (or 0 if there is an error).
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
395 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
396 * @see CircularQueueVoid_Size
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
397 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
398 void* CircularQueueVoid_Back(CircularQueueVoid* queue);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
399
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
400 /**
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
401 * This gets the current number of entries that are in the queue.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
402 * This is number is not to be confused with the MaxSize.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
403 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
404 * @param queue The pointer to the CircularQueue instance.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
405 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
406 * @return Returns the number of entries currently in queue, or 0 if
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
407 * there is an error.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
408 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
409 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
410 unsigned int CircularQueueVoid_Size(CircularQueueVoid* queue);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
411
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
412 /**
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
413 * This gets the maximum number of entries that are allowed in the queue at
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
414 * a given time.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
415 * This is the number that you used in the CreateQueue function.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
416 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
417 * @param queue The pointer to the CircularQueue instance.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
418 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
419 * @return Returns the maximum number of entries allowed in the queue.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
420 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
421 unsigned int CircularQueueVoid_MaxSize(CircularQueueVoid* queue);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
422 /**
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
423 * This empties the entire queue.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
424 * This will remove all entries that are in the queue.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
425 * This does not destroy any memory. Use FreeQueue() to actually destroy
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
426 * the queue.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
427 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
428 * @param queue The pointer to the CircularQueue instance.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
429 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
430 void CircularQueueVoid_Clear(CircularQueueVoid* queue);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
431
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
432 /* Not implemented for void* */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
433 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
434 void CircularQueueVoid_Print(CircularQueueVoid* queue);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
435 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
436
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
437
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
438
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
439
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
440 /* Ends C function definitions when using C++ */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
441 #ifdef __cplusplus
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
442 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
443 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
444
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
445
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
446
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
447 #endif /* C_CIRCULAR_QUEUE_H */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
448
|