Merge pull request #44 from akozumpl/archs
[platform/upstream/libsolv.git] / src / bitmap.c
index 0485945..1bf1666 100644 (file)
@@ -7,7 +7,7 @@
 
 /*
  * bitmap.c
- * 
+ *
  */
 
 #include <stdlib.h>
@@ -21,14 +21,14 @@ void
 map_init(Map *m, int n)
 {
   m->size = (n + 7) >> 3;
-  m->map = m->size ? sat_calloc(m->size, 1) : 0;
+  m->map = m->size ? solv_calloc(m->size, 1) : 0;
 }
 
 /* destructor */
 void
 map_free(Map *m)
 {
-  m->map = sat_free(m->map);
+  m->map = solv_free(m->map);
   m->size = 0;
 }
 
@@ -39,7 +39,7 @@ map_init_clone(Map *t, Map *s)
   t->size = s->size;
   if (s->size)
     {
-      t->map = sat_malloc(s->size);
+      t->map = solv_malloc(s->size);
       memcpy(t->map, s->map, s->size);
     }
   else
@@ -53,10 +53,48 @@ map_grow(Map *m, int n)
   n = (n + 7) >> 3;
   if (m->size < n)
     {
-      m->map = sat_realloc(m->map, n);
+      m->map = solv_realloc(m->map, n);
       memset(m->map + m->size, 0, n - m->size);
       m->size = n;
     }
 }
 
+/* bitwise-ands maps t and s, stores the result in t. */
+void
+map_and(Map *t, 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, 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)
+{
+    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++;
+}
+
 /* EOF */