Back to index

php5  5.3.10
queue.h
Go to the documentation of this file.
00001 /* 
00002  * Date last modified: Jan 2001
00003  * Modifications by Dan Libby (dan@libby.com), including:
00004  *  - various fixes, null checks, etc
00005  *  - addition of Q_Iter funcs, macros
00006  */
00007 
00008 /*
00009  *  File : q.h
00010  *
00011  *  Peter Yard  02 Jan 1993.
00012  *
00013  *  Disclaimer: This code is released to the public domain.
00014  */
00015 
00016 #ifndef Q__H
00017 #define Q__H
00018 
00019 #ifndef False_
00020    #define False_ 0
00021 #endif
00022 
00023 #ifndef True_
00024    #define True_ 1
00025 #endif
00026 
00027 typedef struct nodeptr datanode;
00028 
00029 typedef struct nodeptr {
00030    void        *data ;
00031    datanode    *prev, *next ;
00032 } node ;
00033 
00034 /* For external use with Q_Iter* funcs */
00035 typedef struct nodeptr* q_iter;
00036 
00037 typedef struct {
00038    node        *head, *tail, *cursor;
00039    int         size, sorted, item_deleted;
00040 } queue;
00041 
00042 typedef  struct {
00043    void        *dataptr;
00044    node        *loc ;
00045 } index_elt ;
00046 
00047 
00048 int    Q_Init(queue  *q);
00049 void   Q_Destroy(queue *q);
00050 int    Q_IsEmpty(queue *q);
00051 int    Q_Size(queue *q);
00052 int    Q_AtHead(queue *q);
00053 int    Q_AtTail(queue *q);
00054 int    Q_PushHead(queue *q, void *d);
00055 int    Q_PushTail(queue *q, void *d);
00056 void  *Q_Head(queue *q);
00057 void  *Q_Tail(queue *q);
00058 void  *Q_PopHead(queue *q);
00059 void  *Q_PopTail(queue *q);
00060 void  *Q_Next(queue *q);
00061 void  *Q_Previous(queue *q);
00062 void  *Q_DelCur(queue *q);
00063 void  *Q_Get(queue *q);
00064 int    Q_Put(queue *q, void *data);
00065 int    Q_Sort(queue *q, int (*Comp)(const void *, const void *));
00066 int    Q_Find(queue *q, void *data,
00067               int (*Comp)(const void *, const void *));
00068 void  *Q_Seek(queue *q, void *data,
00069               int (*Comp)(const void *, const void *));
00070 int    Q_Insert(queue *q, void *data,
00071                 int (*Comp)(const void *, const void *));
00072 
00073 /* read only funcs for iterating through queue. above funcs modify queue */
00074 q_iter Q_Iter_Head(queue *q);
00075 q_iter Q_Iter_Tail(queue *q);
00076 q_iter Q_Iter_Next(q_iter qi);
00077 q_iter Q_Iter_Prev(q_iter qi);
00078 void*  Q_Iter_Get(q_iter qi);
00079 int    Q_Iter_Put(q_iter qi, void* data); /* not read only! here for completeness. */
00080 void*  Q_Iter_Del(queue *q, q_iter iter); /* not read only! here for completeness. */
00081 
00082 /* Fast (macro'd) versions of above */
00083 #define Q_Iter_Head_F(q) (q ? (q_iter)((queue*)q)->head : NULL)
00084 #define Q_Iter_Tail_F(q) (q ? (q_iter)((queue*)q)->tail : NULL)
00085 #define Q_Iter_Next_F(qi) (qi ? (q_iter)((node*)qi)->next : NULL)
00086 #define Q_Iter_Prev_F(qi) (qi ? (q_iter)((node*)qi)->prev : NULL)
00087 #define Q_Iter_Get_F(qi) (qi ? ((node*)qi)->data : NULL)
00088 
00089 #endif /* Q__H */