2 * Date last modified: Jan 2001
3 * Modifications by Dan Libby (dan@libby.com), including:
4 * - various fixes, null checks, etc
5 * - addition of Q_Iter funcs, macros
11 * Peter Yard 02 Jan 1993.
13 * Disclaimer: This code is released to the public domain.
27 typedef struct nodeptr datanode;
29 typedef struct nodeptr {
31 datanode *prev, *next ;
34 /* For external use with Q_Iter* funcs */
35 typedef struct nodeptr* q_iter;
38 node *head, *tail, *cursor;
39 int size, sorted, item_deleted;
49 void Q_Destroy(queue *q);
50 int Q_IsEmpty(queue *q);
52 int Q_AtHead(queue *q);
53 int Q_AtTail(queue *q);
54 int Q_PushHead(queue *q, void *d);
55 int Q_PushTail(queue *q, void *d);
56 void *Q_Head(queue *q);
57 void *Q_Tail(queue *q);
58 void *Q_PopHead(queue *q);
59 void *Q_PopTail(queue *q);
60 void *Q_Next(queue *q);
61 void *Q_Previous(queue *q);
62 void *Q_DelCur(queue *q);
63 void *Q_Get(queue *q);
64 int Q_Put(queue *q, void *data);
65 int Q_Sort(queue *q, int (*Comp)(const void *, const void *));
66 int Q_Find(queue *q, void *data,
67 int (*Comp)(const void *, const void *));
68 void *Q_Seek(queue *q, void *data,
69 int (*Comp)(const void *, const void *));
70 int Q_Insert(queue *q, void *data,
71 int (*Comp)(const void *, const void *));
73 /* read only funcs for iterating through queue. above funcs modify queue */
74 q_iter Q_Iter_Head(queue *q);
75 q_iter Q_Iter_Tail(queue *q);
76 q_iter Q_Iter_Next(q_iter qi);
77 q_iter Q_Iter_Prev(q_iter qi);
78 void* Q_Iter_Get(q_iter qi);
79 int Q_Iter_Put(q_iter qi, void* data); /* not read only! here for completeness. */
80 void* Q_Iter_Del(queue *q, q_iter iter); /* not read only! here for completeness. */
82 /* Fast (macro'd) versions of above */
83 #define Q_Iter_Head_F(q) (q ? (q_iter)((queue*)q)->head : NULL)
84 #define Q_Iter_Tail_F(q) (q ? (q_iter)((queue*)q)->tail : NULL)
85 #define Q_Iter_Next_F(qi) (qi ? (q_iter)((node*)qi)->next : NULL)
86 #define Q_Iter_Prev_F(qi) (qi ? (q_iter)((node*)qi)->prev : NULL)
87 #define Q_Iter_Get_F(qi) (qi ? ((node*)qi)->data : NULL)