- add map_or and queue_prealloc
authorMichael Schroeder <mls@suse.de>
Mon, 16 Apr 2012 15:08:07 +0000 (17:08 +0200)
committerMichael Schroeder <mls@suse.de>
Mon, 16 Apr 2012 15:08:07 +0000 (17:08 +0200)
src/bitmap.c
src/bitmap.h
src/libsolv.ver
src/queue.c
src/queue.h
src/rules.c

index 21630ad..f304e6b 100644 (file)
@@ -59,7 +59,7 @@ map_grow(Map *m, int n)
     }
 }
 
-/* bitwise-ands same-sized maps t and s, stores the result in t. */
+/* bitwise-ands maps t and s, stores the result in t. */
 void
 map_and(Map *t, Map *s)
 {
@@ -71,6 +71,20 @@ map_and(Map *t, Map *s)
        *ti++ &= *si++;
 }
 
+/* bitwise-ors maps t and s, stores the result in t. */
+void
+map_or(Map *t, Map *s)
+{
+    unsigned char *ti, *si, *end;
+    if (t->size < s->size)
+      map_grow(t, s->size << 3);
+    ti = t->map;
+    si = s->map;
+    end = ti + (t->size < s->size ? t->size : s->size);
+    while (ti < end)
+       *ti++ |= *si++;
+}
+
 /* remove all set bits in s from t. */
 void
 map_subtract(Map *t, Map *s)
index 3a60c51..c6993ca 100644 (file)
@@ -35,6 +35,7 @@ extern void map_init_clone(Map *t, Map *s);
 extern void map_grow(Map *m, int n);
 extern void map_free(Map *m);
 extern void map_and(Map *t, Map *s);
+extern void map_or(Map *t, Map *s);
 extern void map_subtract(Map *t, Map *s);
 
 static inline void map_empty(Map *m)
index a2e100c..0e141ef 100644 (file)
@@ -32,6 +32,7 @@ SOLV_1.0 {
                map_grow;
                map_init;
                map_init_clone;
+               map_or;
                policy_filter_unwanted;
                policy_findupdatepackages;
                policy_illegal2str;
@@ -113,6 +114,7 @@ SOLV_1.0 {
                queue_insert;
                queue_insert2;
                queue_insertn;
+               queue_prealloc;
                repo_add_deparray;
                repo_add_idarray;
                repo_add_poolstr_array;
index 4fe0799..60b1749 100644 (file)
@@ -188,3 +188,19 @@ queue_deleten(Queue *q, int pos, int n)
   q->left += n;
   q->count -= n;
 }
+
+/* allocate room for n more elements */
+void
+queue_prealloc(Queue *q, int n)
+{
+  int off;
+  if (n <= 0 || q->left >= n)
+    return;
+  if (!q->alloc)
+    queue_alloc_one(q);
+  off = q->elements - q->alloc;
+  q->alloc = solv_realloc2(q->alloc, off + q->count + n + EXTRA_SPACE, sizeof(Id));
+  q->elements = q->alloc + off;
+  q->left = n + EXTRA_SPACE;
+}
+
index e8b39fe..d5380c3 100644 (file)
@@ -114,5 +114,6 @@ 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);
+extern void queue_prealloc(Queue *q, int n);
 
 #endif /* LIBSOLV_QUEUE_H */
index ca4be2c..4128903 100644 (file)
@@ -2926,9 +2926,7 @@ solver_get_unneeded(Solver *solv, Queue *unneededq, int filtered)
 
       nrequires = solv_calloc(count, sizeof(Id));
       queue_init(&edges);
-      /* pre-size */
-      queue_insertn(&edges, 0, count * 4 + 10);
-      queue_empty(&edges);
+      queue_prealloc(&edges, count * 4 + 10);  /* pre-size */
 
       /*
        * Go through the solvables in the nodes queue and create edges for