From: Michael Schroeder Date: Mon, 16 Apr 2012 15:08:07 +0000 (+0200) Subject: - add map_or and queue_prealloc X-Git-Tag: BASE-SuSE-Code-12_2-Branch~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8cf2c0ad50a294ea14538b87cb7f34ea540c36f5;p=thirdparty%2Flibsolv.git - add map_or and queue_prealloc --- diff --git a/src/bitmap.c b/src/bitmap.c index 21630ade..f304e6b9 100644 --- a/src/bitmap.c +++ b/src/bitmap.c @@ -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) diff --git a/src/bitmap.h b/src/bitmap.h index 3a60c517..c6993caa 100644 --- a/src/bitmap.h +++ b/src/bitmap.h @@ -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) diff --git a/src/libsolv.ver b/src/libsolv.ver index a2e100c6..0e141ef4 100644 --- a/src/libsolv.ver +++ b/src/libsolv.ver @@ -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; diff --git a/src/queue.c b/src/queue.c index 4fe07999..60b17491 100644 --- a/src/queue.c +++ b/src/queue.c @@ -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; +} + diff --git a/src/queue.h b/src/queue.h index e8b39fe5..d5380c32 100644 --- a/src/queue.h +++ b/src/queue.h @@ -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 */ diff --git a/src/rules.c b/src/rules.c index ca4be2c8..4128903c 100644 --- a/src/rules.c +++ b/src/rules.c @@ -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