summaryrefslogtreecommitdiff
path: root/src/queue.c
diff options
context:
space:
mode:
authorMichael Schroeder <mls@suse.de>2009-06-08 17:20:20 +0200
committerMichael Schroeder <mls@suse.de>2009-06-08 17:20:20 +0200
commit3ef06f9901829dc03aaf685faf8612170f4c909c (patch)
tree541e569507955e0bc02fabde8e6d4203b57c0f56 /src/queue.c
parent93ed9cc41fadfd5eeb1928e9028f5f2f600fb752 (diff)
downloadlibsolv-3ef06f9901829dc03aaf685faf8612170f4c909c.tar.gz
libsolv-3ef06f9901829dc03aaf685faf8612170f4c909c.tar.bz2
libsolv-3ef06f9901829dc03aaf685faf8612170f4c909c.zip
- update transaction ordering code
- add queue insert/delete functions
Diffstat (limited to 'src/queue.c')
-rw-r--r--src/queue.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/queue.c b/src/queue.c
index 345050f..38fd765 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -75,3 +75,54 @@ queue_alloc_one(Queue *q)
}
}
+void
+queue_insert(Queue *q, int pos, Id id)
+{
+ queue_push(q, id); /* make room */
+ if (pos < q->count - 1)
+ {
+ memmove(q->elements + pos + 1, q->elements + pos, (q->count - 1 - pos) * sizeof(Id));
+ q->elements[pos] = id;
+ }
+}
+
+void
+queue_delete(Queue *q, int pos)
+{
+ if (pos >= q->count)
+ return;
+ if (pos < q->count - 1)
+ memmove(q->elements + pos, q->elements + pos + 1, (q->count - 1 - pos) * sizeof(Id));
+ q->left++;
+ q->count--;
+}
+
+void
+queue_insert2(Queue *q, int pos, Id id1, Id id2)
+{
+ queue_push(q, id1); /* make room */
+ queue_push(q, id2); /* make room */
+ if (pos < q->count - 2)
+ {
+ memmove(q->elements + pos + 2, q->elements + pos, (q->count - 2 - pos) * sizeof(Id));
+ q->elements[pos] = id1;
+ q->elements[pos] = id2;
+ }
+}
+
+void
+queue_delete2(Queue *q, int pos)
+{
+ if (pos >= q->count)
+ return;
+ if (pos == q->count - 1)
+ {
+ q->left++;
+ q->count--;
+ return;
+ }
+ if (pos < q->count - 2)
+ memmove(q->elements + pos, q->elements + pos + 2, (q->count - 2 - pos) * sizeof(Id));
+ q->left += 2;
+ q->count -= 2;
+}