2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
22 q->alloc = q->elements = 0;
23 q->count = q->left = 0;
27 queue_init_clone(Queue *t, Queue *s)
29 t->alloc = t->elements = sat_malloc2(s->count + 8, sizeof(Id));
31 memcpy(t->alloc, s->elements, s->count * sizeof(Id));
37 queue_init_buffer(Queue *q, Id *buf, int size)
50 q->alloc = q->elements = 0;
51 q->count = q->left = 0;
55 queue_alloc_one(Queue *q)
59 /* queue was created with queue_init_buf */
60 q->alloc = sat_malloc2(q->count + 8, sizeof(Id));
62 memcpy(q->alloc, q->elements, q->count * sizeof(Id));
63 q->elements = q->alloc;
66 else if (q->alloc != q->elements)
68 int l = q->elements - q->alloc;
70 memmove(q->alloc, q->elements, q->count * sizeof(Id));
76 q->elements = q->alloc = sat_realloc2(q->alloc, q->count + 8, sizeof(Id));
81 /* make room for an element in front of queue */
83 queue_alloc_one_head(Queue *q)
86 if (!q->alloc || !q->left)
88 l = q->left > 8 ? 8 : q->left;
90 memmove(q->elements + l, q->elements, q->count * sizeof(Id));
96 queue_insert(Queue *q, int pos, Id id)
98 queue_push(q, id); /* make room */
99 if (pos < q->count - 1)
101 memmove(q->elements + pos + 1, q->elements + pos, (q->count - 1 - pos) * sizeof(Id));
102 q->elements[pos] = id;
107 queue_delete(Queue *q, int pos)
111 if (pos < q->count - 1)
112 memmove(q->elements + pos, q->elements + pos + 1, (q->count - 1 - pos) * sizeof(Id));
118 queue_insert2(Queue *q, int pos, Id id1, Id id2)
120 queue_push(q, id1); /* make room */
121 queue_push(q, id2); /* make room */
122 if (pos < q->count - 2)
124 memmove(q->elements + pos + 2, q->elements + pos, (q->count - 2 - pos) * sizeof(Id));
125 q->elements[pos] = id1;
126 q->elements[pos + 1] = id2;
131 queue_delete2(Queue *q, int pos)
135 if (pos == q->count - 1)
141 if (pos < q->count - 2)
142 memmove(q->elements + pos, q->elements + pos + 2, (q->count - 2 - pos) * sizeof(Id));