Lines Matching refs:bm
66 struct util_bitmask *bm; in util_bitmask_create() local
68 bm = MALLOC_STRUCT(util_bitmask); in util_bitmask_create()
69 if(!bm) in util_bitmask_create()
72 bm->words = (util_bitmask_word *)CALLOC(UTIL_BITMASK_INITIAL_WORDS, sizeof(util_bitmask_word)); in util_bitmask_create()
73 if(!bm->words) { in util_bitmask_create()
74 FREE(bm); in util_bitmask_create()
78 bm->size = UTIL_BITMASK_INITIAL_WORDS * UTIL_BITMASK_BITS_PER_WORD; in util_bitmask_create()
79 bm->filled = 0; in util_bitmask_create()
81 return bm; in util_bitmask_create()
89 util_bitmask_resize(struct util_bitmask *bm, in util_bitmask_resize() argument
100 if(bm->size >= minimum_size) in util_bitmask_resize()
103 assert(bm->size % UTIL_BITMASK_BITS_PER_WORD == 0); in util_bitmask_resize()
104 new_size = bm->size; in util_bitmask_resize()
108 if(new_size < bm->size) in util_bitmask_resize()
114 new_words = (util_bitmask_word *)REALLOC((void *)bm->words, in util_bitmask_resize()
115 bm->size / UTIL_BITMASK_BITS_PER_BYTE, in util_bitmask_resize()
120 memset(new_words + bm->size/UTIL_BITMASK_BITS_PER_WORD, in util_bitmask_resize()
122 (new_size - bm->size)/UTIL_BITMASK_BITS_PER_BYTE); in util_bitmask_resize()
124 bm->size = new_size; in util_bitmask_resize()
125 bm->words = new_words; in util_bitmask_resize()
135 util_bitmask_filled_set(struct util_bitmask *bm, in util_bitmask_filled_set() argument
138 assert(bm->filled <= bm->size); in util_bitmask_filled_set()
139 assert(index < bm->size); in util_bitmask_filled_set()
141 if(index == bm->filled) { in util_bitmask_filled_set()
142 ++bm->filled; in util_bitmask_filled_set()
143 assert(bm->filled <= bm->size); in util_bitmask_filled_set()
148 util_bitmask_filled_unset(struct util_bitmask *bm, in util_bitmask_filled_unset() argument
151 assert(bm->filled <= bm->size); in util_bitmask_filled_unset()
152 assert(index < bm->size); in util_bitmask_filled_unset()
154 if(index < bm->filled) in util_bitmask_filled_unset()
155 bm->filled = index; in util_bitmask_filled_unset()
160 util_bitmask_add(struct util_bitmask *bm) in util_bitmask_add() argument
166 assert(bm); in util_bitmask_add()
169 word = bm->filled / UTIL_BITMASK_BITS_PER_WORD; in util_bitmask_add()
170 bit = bm->filled % UTIL_BITMASK_BITS_PER_WORD; in util_bitmask_add()
172 while(word < bm->size / UTIL_BITMASK_BITS_PER_WORD) { in util_bitmask_add()
174 if(!(bm->words[word] & mask)) in util_bitmask_add()
176 ++bm->filled; in util_bitmask_add()
187 if(!util_bitmask_resize(bm, bm->filled)) in util_bitmask_add()
190 assert(!(bm->words[word] & mask)); in util_bitmask_add()
191 bm->words[word] |= mask; in util_bitmask_add()
193 return bm->filled++; in util_bitmask_add()
198 util_bitmask_set(struct util_bitmask *bm, in util_bitmask_set() argument
205 assert(bm); in util_bitmask_set()
208 if(!util_bitmask_resize(bm, index)) in util_bitmask_set()
215 bm->words[word] |= mask; in util_bitmask_set()
217 util_bitmask_filled_set(bm, index); in util_bitmask_set()
224 util_bitmask_clear(struct util_bitmask *bm, in util_bitmask_clear() argument
231 assert(bm); in util_bitmask_clear()
233 if(index >= bm->size) in util_bitmask_clear()
240 bm->words[word] &= ~mask; in util_bitmask_clear()
242 util_bitmask_filled_unset(bm, index); in util_bitmask_clear()
247 util_bitmask_get(struct util_bitmask *bm, in util_bitmask_get() argument
254 assert(bm); in util_bitmask_get()
256 if(index < bm->filled) { in util_bitmask_get()
257 assert(bm->words[word] & mask); in util_bitmask_get()
261 if(index >= bm->size) in util_bitmask_get()
264 if(bm->words[word] & mask) { in util_bitmask_get()
265 util_bitmask_filled_set(bm, index); in util_bitmask_get()
274 util_bitmask_get_next_index(struct util_bitmask *bm, in util_bitmask_get_next_index() argument
281 if(index < bm->filled) { in util_bitmask_get_next_index()
282 assert(bm->words[word] & mask); in util_bitmask_get_next_index()
286 if(index >= bm->size) { in util_bitmask_get_next_index()
291 while(word < bm->size / UTIL_BITMASK_BITS_PER_WORD) { in util_bitmask_get_next_index()
293 if(bm->words[word] & mask) { in util_bitmask_get_next_index()
294 if(index == bm->filled) { in util_bitmask_get_next_index()
295 ++bm->filled; in util_bitmask_get_next_index()
296 assert(bm->filled <= bm->size); in util_bitmask_get_next_index()
314 util_bitmask_get_first_index(struct util_bitmask *bm) in util_bitmask_get_first_index() argument
316 return util_bitmask_get_next_index(bm, 0); in util_bitmask_get_first_index()
321 util_bitmask_destroy(struct util_bitmask *bm) in util_bitmask_destroy() argument
323 assert(bm); in util_bitmask_destroy()
325 FREE(bm->words); in util_bitmask_destroy()
326 FREE(bm); in util_bitmask_destroy()