Permalink
Browse files

- add map_or and queue_prealloc

  • Loading branch information...
1 parent 6f8b404 commit 8cf2c0ad50a294ea14538b87cb7f34ea540c36f5 @mlschroe mlschroe committed Apr 16, 2012
Showing with 36 additions and 4 deletions.
  1. +15 −1 src/bitmap.c
  2. +1 −0 src/bitmap.h
  3. +2 −0 src/libsolv.ver
  4. +16 −0 src/queue.c
  5. +1 −0 src/queue.h
  6. +1 −3 src/rules.c
View
16 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)
View
1 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)
View
2 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;
View
16 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;
+}
+
View
1 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 */
View
4 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

0 comments on commit 8cf2c0a

Please sign in to comment.