Add ENABLE_COMPLEX_DEPS flag
[platform/upstream/libsolv.git] / src / bitmap.c
index 5a8dcd8..4e8adbd 100644 (file)
@@ -7,7 +7,7 @@
 
 /*
  * bitmap.c
- * 
+ *
  */
 
 #include <stdlib.h>
@@ -32,18 +32,18 @@ map_free(Map *m)
   m->size = 0;
 }
 
-/* copy constructor t <- s */
+/* copy constructor target <- source */
 void
-map_init_clone(Map *t, Map *s)
+map_init_clone(Map *target, const Map *source)
 {
-  t->size = s->size;
-  if (s->size)
+  target->size = source->size;
+  if (source->size)
     {
-      t->map = solv_malloc(s->size);
-      memcpy(t->map, s->map, s->size);
+      target->map = solv_malloc(source->size);
+      memcpy(target->map, source->map, source->size);
     }
   else
-    t->map = 0;
+    target->map = 0;
 }
 
 /* grow a map */
@@ -59,28 +59,52 @@ 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, const Map *s)
+{
+  unsigned char *ti, *si, *end;
+  ti = t->map;
+  si = s->map;
+  end = ti + (t->size < s->size ? t->size : s->size);
+  while (ti < end)
+    *ti++ &= *si++;
+}
+
+/* bitwise-ors maps t and s, stores the result in t. */
+void
+map_or(Map *t, const 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_and(Map *t, Map *s)
+map_subtract(Map *t, const Map *s)
 {
-    unsigned char *ti, *si, *end;
-    ti = t->map;
-    si = s->map;
-    end = ti + t->size;
-    while (ti < end)
-       *ti++ &= *si++;
+  unsigned char *ti, *si, *end;
+  ti = t->map;
+  si = s->map;
+  end = ti + (t->size < s->size ? t->size : s->size);
+  while (ti < end)
+    *ti++ &= ~*si++;
 }
 
-/* like map_and but negates value in s first, i.e. t & ~s */
 void
-map_and_not(Map *t, Map *s)
+map_invertall(Map *m)
 {
-    unsigned char *ti, *si, *end;
-    ti = t->map;
-    si = s->map;
-    end = ti + t->size;
-    while (ti < end)
-       *ti++ &= ~*si++;
+  unsigned char *ti, *end;
+  ti = m->map;
+  end = ti + m->size;
+  while (ti < end)
+    *ti++ ^= 0xff;
 }
 
 /* EOF */