00001 /* 00002 * Copyright (c) 2007, Novell Inc. 00003 * 00004 * This program is licensed under the BSD license, read LICENSE.BSD 00005 * for further information 00006 */ 00007 00008 /* 00009 * bitmap.c 00010 * 00011 */ 00012 00013 #include <stdlib.h> 00014 #include <string.h> 00015 00016 #include "bitmap.h" 00017 #include "util.h" 00018 00019 /* constructor */ 00020 void 00021 map_init(Map *m, int n) 00022 { 00023 m->size = (n + 7) >> 3; 00024 m->map = m->size ? sat_calloc(m->size, 1) : 0; 00025 } 00026 00027 /* destructor */ 00028 void 00029 map_free(Map *m) 00030 { 00031 m->map = sat_free(m->map); 00032 m->size = 0; 00033 } 00034 00035 /* copy constructor t <- s */ 00036 void 00037 map_init_clone(Map *t, Map *s) 00038 { 00039 t->size = s->size; 00040 if (s->size) 00041 { 00042 t->map = sat_malloc(s->size); 00043 memcpy(t->map, s->map, s->size); 00044 } 00045 else 00046 t->map = 0; 00047 } 00048 00049 /* grow a map */ 00050 void 00051 map_grow(Map *m, int n) 00052 { 00053 n = (n + 7) >> 3; 00054 if (m->size < n) 00055 { 00056 m->map = sat_realloc(m->map, n); 00057 memset(m->map + m->size, 0, n - m->size); 00058 m->size = n; 00059 } 00060 } 00061 00062 /* EOF */