2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
13 #ifndef LIBSOLV_QUEUE_H
14 #define LIBSOLV_QUEUE_H
16 #include "pooltypes.h"
22 typedef struct _Queue {
23 Id *elements; /* pointer to elements */
24 int count; /* current number of elements in queue */
25 Id *alloc; /* this is whats actually allocated, elements > alloc if shifted */
26 int left; /* space left in alloc *after* elements+count */
30 extern void queue_alloc_one(Queue *q); /* internal */
31 extern void queue_alloc_one_head(Queue *q); /* internal */
39 q->left += (q->elements - q->alloc) + q->count;
40 q->elements = q->alloc;
53 return *q->elements++;
62 return q->elements[--q->count];
66 queue_unshift(Queue *q, Id id)
68 if (!q->alloc || q->alloc == q->elements)
69 queue_alloc_one_head(q);
75 queue_push(Queue *q, Id id)
79 q->elements[q->count++] = id;
84 queue_pushunique(Queue *q, Id id)
87 for (i = q->count; i > 0; )
88 if (q->elements[--i] == id)
94 queue_push2(Queue *q, Id id1, Id id2)
101 queue_truncate(Queue *q, int n)
105 q->left += q->count - n;
110 extern void queue_init(Queue *q);
111 extern void queue_init_buffer(Queue *q, Id *buf, int size);
112 extern void queue_init_clone(Queue *t, Queue *s);
113 extern void queue_free(Queue *q);
115 extern void queue_insert(Queue *q, int pos, Id id);
116 extern void queue_insert2(Queue *q, int pos, Id id1, Id id2);
117 extern void queue_insertn(Queue *q, int pos, int n, Id *elements);
118 extern void queue_delete(Queue *q, int pos);
119 extern void queue_delete2(Queue *q, int pos);
120 extern void queue_deleten(Queue *q, int pos, int n);
121 extern void queue_prealloc(Queue *q, int n);
127 #endif /* LIBSOLV_QUEUE_H */