12 struct Queue * createQueue() {
13 struct Queue * queue = (struct Queue *)RUNMALLOC(sizeof(struct Queue));
19 void initQueue(struct Queue * q) {
24 void freeQueue(struct Queue * q) {
28 struct QueueItem * addNewItem(struct Queue * queue, void * ptr) {
29 struct QueueItem * item=RUNMALLOC(sizeof(struct QueueItem));
32 if (queue->head==NULL) {
38 item->next=queue->head;
40 queue->head->prev=item;
46 struct QueueItem * addNewItemBack(struct Queue * queue, void * ptr) {
47 struct QueueItem * item=RUNMALLOC(sizeof(struct QueueItem));
50 if (queue->tail==NULL) {
56 item->prev=queue->tail;
58 queue->tail->next=item;
65 struct Queue * createQueue_I() {
66 struct Queue * queue = (struct Queue *)RUNMALLOC_I(sizeof(struct Queue));
72 struct QueueItem * addNewItem_I(struct Queue * queue, void * ptr) {
73 struct QueueItem * item=RUNMALLOC_I(sizeof(struct QueueItem));
76 if (queue->head==NULL) {
80 item->next=queue->head;
81 queue->head->prev=item;
88 struct QueueItem * getTail(struct Queue * queue) {
92 struct QueueItem * getHead(struct Queue * queue) {
96 struct QueueItem * getNextQueueItem(struct QueueItem * qi) {
100 struct QueueItem * findItem(struct Queue * queue, void *ptr) {
101 struct QueueItem * item=queue->head;
103 if (item->objectptr==ptr)
110 void removeItem(struct Queue * queue, struct QueueItem * item) {
111 struct QueueItem * prev=item->prev;
112 struct QueueItem * next=item->next;
113 if (queue->head==item)
117 if (queue->tail==item)
124 void * getItem(struct Queue * queue) {
125 struct QueueItem * q=queue->head;
126 void * ptr=q->objectptr;
127 if(queue->tail==queue->head) {
133 if(queue->tail == q) {
140 void * getItemBack(struct Queue * queue) {
141 struct QueueItem * q=queue->tail;
142 void * ptr=q->objectptr;
143 if(queue->head==queue->tail) {
153 void * peekItem(struct Queue * queue) {
154 struct QueueItem * q=queue->head;
155 void * ptr=q->objectptr;
159 void * peekItemBack(struct Queue * queue) {
160 struct QueueItem * q=queue->tail;
161 void * ptr=q->objectptr;
165 void clearQueue(struct Queue * queue) {
166 struct QueueItem * item=queue->head;
168 struct QueueItem * next=item->next;
172 queue->head=queue->tail=NULL;
177 int assertQueue(struct Queue * queue) {
179 struct QueueItem* i = queue->head;
181 if( i == NULL && queue->tail != NULL ) {
187 if( queue->head == i && i->prev != NULL ) {
191 if( i->prev == NULL ) {
192 if( queue->head != i ) {
198 if( i->prev->next == NULL ) {
200 } else if( i->prev->next != i ) {
205 if( i->next == NULL ) {
206 if( queue->tail != i ) {
212 if( i->next->prev == NULL ) {
214 } else if( i->next->prev != i ) {
219 if( queue->tail == i && i->next != NULL ) {
223 i = getNextQueueItem(i);
229 void printQueue(struct Queue * queue) {
232 printf("Queue empty? %d\n", isEmpty(queue));
238 i = getNextQueueItem(i);
242 printf("[%08x] ", (int)queue->head);
245 printf("[%08x] ", (int)i);
246 i = getNextQueueItem(i);
248 printf("[%08x]\n", (int)queue->tail);
253 printf("[%08x] ", (int)(i->next));
254 i = getNextQueueItem(i);
261 printf("[%08x] ", (int)(i->prev));
262 i = getNextQueueItem(i);