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"
18 typedef struct _Queue {
19 Id *elements; /* pointer to elements */
20 int count; /* current number of elements in queue */
21 Id *alloc; /* this is whats actually allocated, elements > alloc if shifted */
22 int left; /* space left in alloc *after* elements+count */
26 extern void queue_alloc_one(Queue *q); /* internal */
27 extern void queue_alloc_one_head(Queue *q); /* internal */
35 q->left += (q->elements - q->alloc) + q->count;
36 q->elements = q->alloc;
49 return *q->elements++;
58 return q->elements[--q->count];
62 queue_unshift(Queue *q, Id id)
64 if (!q->alloc || q->alloc == q->elements)
65 queue_alloc_one_head(q);
71 queue_push(Queue *q, Id id)
75 q->elements[q->count++] = id;
80 queue_pushunique(Queue *q, Id id)
83 for (i = q->count; i > 0; )
84 if (q->elements[--i] == id)
90 queue_push2(Queue *q, Id id1, Id id2)
97 queue_truncate(Queue *q, int n)
101 q->left += q->count - n;
106 extern void queue_init(Queue *q);
107 extern void queue_init_buffer(Queue *q, Id *buf, int size);
108 extern void queue_init_clone(Queue *t, Queue *s);
109 extern void queue_free(Queue *q);
111 extern void queue_insert(Queue *q, int pos, Id id);
112 extern void queue_insert2(Queue *q, int pos, Id id1, Id id2);
113 extern void queue_insertn(Queue *q, int pos, int n);
114 extern void queue_delete(Queue *q, int pos);
115 extern void queue_delete2(Queue *q, int pos);
116 extern void queue_deleten(Queue *q, int pos, int n);
117 extern void queue_prealloc(Queue *q, int n);
119 #endif /* LIBSOLV_QUEUE_H */