- rename queue* to queue_*, inline a bit more
[platform/upstream/libsolv.git] / src / queue.h
1 /*
2  * queue.h
3  * 
4  */
5
6 #ifndef QUEUE_H
7 #define QUEUE_H
8
9 #include "pooltypes.h"
10
11 typedef struct _Queue {
12   Id *elements;         // current elements
13   int count;            // current number of elements (minimal size for elements pointer)
14   Id *alloc;            // this is whats actually allocated, elements > alloc if shifted
15   int left;             // space left in alloc *after* elements+count
16 } Queue;
17
18
19 extern void queue_alloc_one(Queue *q);
20
21 // clear queue
22 static inline void
23 queue_empty(Queue *q)
24 {
25   if (q->alloc)
26     {
27       q->left += (q->elements - q->alloc) + q->count;
28       q->elements = q->alloc;
29     }
30   else
31     q->left += q->count;
32   q->count = 0;
33 }
34
35 static inline Id
36 queue_shift(Queue *q)
37 {
38   if (!q->count)
39     return 0;
40   q->count--;
41   return *q->elements++;
42 }
43
44 static inline void
45 queue_push(Queue *q, Id id)
46 {
47   if (!q->left)
48     queue_alloc_one(q);
49   q->elements[q->count++] = id;
50   q->left--;
51 }
52
53 static inline void
54 queue_pushunique(Queue *q, Id id)
55 {
56   int i;
57   for (i = q->count; i > 0; )
58     if (q->elements[--i] == id)
59       return;
60   queue_push(q, id);
61 }
62
63 extern void queue_clone(Queue *t, Queue *s);
64 extern void queue_init(Queue *q);
65 extern void queue_init_buffer(Queue *q, Id *buf, int size);
66 extern void queue_free(Queue *q);
67
68 #endif /* QUEUE_H */