#include "pooltypes.h"
typedef struct _Queue {
- Id *elements; // current elements
- int count; // current number of elements (minimal size for elements pointer)
- Id *alloc; // this is whats actually allocated, elements > alloc if shifted
- int left; // space left in alloc *after* elements+count
+ Id *elements; /* pointer to elements */
+ int count; /* current number of elements in queue */
+ Id *alloc; /* this is whats actually allocated, elements > alloc if shifted */
+ int left; /* space left in alloc *after* elements+count */
} Queue;
-extern void queue_alloc_one(Queue *q);
+extern void queue_alloc_one(Queue *q); /* internal */
+extern void queue_alloc_one_head(Queue *q); /* internal */
-// clear queue
+/* clear queue */
static inline void
queue_empty(Queue *q)
{
return *q->elements++;
}
+static inline Id
+queue_pop(Queue *q)
+{
+ if (!q->count)
+ return 0;
+ q->left++;
+ return q->elements[--q->count];
+}
+
+static inline void
+queue_unshift(Queue *q, Id id)
+{
+ if (!q->alloc || q->alloc == q->elements)
+ queue_alloc_one_head(q);
+ *--q->elements = id;
+ q->count++;
+}
+
static inline void
queue_push(Queue *q, Id id)
{
queue_push(q, id);
}
-extern void queue_clone(Queue *t, Queue *s);
+static inline void
+queue_push2(Queue *q, Id id1, Id id2)
+{
+ queue_push(q, id1);
+ queue_push(q, id2);
+}
+
+static inline void
+queue_truncate(Queue *q, int n)
+{
+ if (q->count > n)
+ {
+ q->left += q->count - n;
+ q->count = n;
+ }
+}
+
extern void queue_init(Queue *q);
extern void queue_init_buffer(Queue *q, Id *buf, int size);
+extern void queue_init_clone(Queue *t, Queue *s);
extern void queue_free(Queue *q);
+extern void queue_insert(Queue *q, int pos, Id id);
+extern void queue_insert2(Queue *q, int pos, Id id1, Id id2);
+extern void queue_insertn(Queue *q, int pos, int n);
+extern void queue_delete(Queue *q, int pos);
+extern void queue_delete2(Queue *q, int pos);
+extern void queue_deleten(Queue *q, int pos, int n);
+
#endif /* SATSOLVER_QUEUE_H */