summaryrefslogtreecommitdiff
path: root/src/queue.c
diff options
context:
space:
mode:
authorMichael Schroeder <mls@suse.de>2009-06-16 18:51:17 +0200
committerMichael Schroeder <mls@suse.de>2009-06-16 18:52:01 +0200
commitac9f5e88cae754434b0edcb8995f0e6b6557695a (patch)
tree8e70e4d633f799254a47297a9c25453fee4cf6ab /src/queue.c
parent86071973440076dbaa31274e42ccbb5baa79ac67 (diff)
downloadlibsolv-ac9f5e88cae754434b0edcb8995f0e6b6557695a.tar.gz
libsolv-ac9f5e88cae754434b0edcb8995f0e6b6557695a.tar.bz2
libsolv-ac9f5e88cae754434b0edcb8995f0e6b6557695a.zip
- add queue_insertn, queue_deleten, queue_truncate
Diffstat (limited to 'src/queue.c')
-rw-r--r--src/queue.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/queue.c b/src/queue.c
index 2f9f75a..fa10339 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -143,3 +143,40 @@ queue_delete2(Queue *q, int pos)
q->left += 2;
q->count -= 2;
}
+
+void
+queue_insertn(Queue *q, int pos, int n)
+{
+ if (n <= 0)
+ return;
+ if (pos > q->count)
+ pos = q->count;
+ if (q->left < n)
+ {
+ int off;
+ if (!q->alloc)
+ queue_alloc_one(q);
+ off = q->elements - q->alloc;
+ q->alloc = sat_realloc2(q->alloc, off + q->count + n + 8, sizeof(Id));
+ q->elements = q->alloc + off;
+ q->left = n + 8;
+ }
+ if (pos < q->count)
+ memmove(q->elements + pos + n, q->elements + pos, (q->count - pos) * sizeof(Id));
+ memset(q->elements + pos, 0, n * sizeof(Id));
+ q->left -= n;
+ q->count += n;
+}
+
+void
+queue_deleten(Queue *q, int pos, int n)
+{
+ if (n <= 0 || pos >= q->count)
+ return;
+ if (pos + n >= q->count)
+ n = q->count - pos;
+ else
+ memmove(q->elements + pos, q->elements + pos + n, (q->count - n - pos) * sizeof(Id));
+ q->left += n;
+ q->count -= n;
+}