#include "bitmap.h"
#include "util.h"
+/* constructor */
void
map_init(Map *m, int n)
{
m->size = (n + 7) >> 3;
- m->map = sat_calloc(m->size, 1);
+ m->map = m->size ? solv_calloc(m->size, 1) : 0;
}
-// free space allocated
+/* destructor */
void
map_free(Map *m)
{
- m->map = sat_free(m->map);
+ m->map = solv_free(m->map);
m->size = 0;
}
-// copy t <- s
+/* copy constructor t <- s */
void
-map_clone(Map *t, Map *s)
+map_init_clone(Map *t, Map *s)
{
t->size = s->size;
- t->map = sat_malloc(s->size);
- memcpy(t->map, s->map, t->size);
+ if (s->size)
+ {
+ t->map = solv_malloc(s->size);
+ memcpy(t->map, s->map, s->size);
+ }
+ else
+ t->map = 0;
}
-// EOF
+/* grow a map */
+void
+map_grow(Map *m, int n)
+{
+ n = (n + 7) >> 3;
+ if (m->size < n)
+ {
+ m->map = solv_realloc(m->map, n);
+ memset(m->map + m->size, 0, n - m->size);
+ m->size = n;
+ }
+}
+
+/* bitwise-ands same-sized 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;
+ while (ti < end)
+ *ti++ &= *si++;
+}
+
+/* EOF */