void bitset_countn_free(bitset_countn_t *counter) { size_t i; for ( i = 0; i <= counter->n; i++) { bitset_malloc_free(counter->words[i]); } bitset_malloc_free(counter->words); bitset_malloc_free(counter); }
unsigned *bitset_countn_count_mask(const bitset_countn_t *counter, const bitset_t *mask) { bitset_word *mask_words = bitset_calloc(1, counter->size * sizeof(bitset_word)); if (!mask_words) { bitset_oom(); } bitset_offset offset = 0; bitset_word word, mask_word; unsigned position; size_t i; for ( i = 0; i < mask->length; i++) { mask_word = mask->buffer[i]; if (BITSET_IS_FILL_WORD(mask_word)) { offset += BITSET_GET_LENGTH(mask_word); if (offset >= counter->size) { offset %= counter->size; } position = BITSET_GET_POSITION(mask_word); if (!position) { continue; } mask_word = BITSET_CREATE_LITERAL(position - 1); } mask_words[offset] |= mask_word; offset++; if (offset >= counter->size) { offset -= counter->size; } } unsigned *counts = bitset_calloc(1, sizeof(unsigned) * counter->n); if (!counts) { bitset_oom(); } size_t offset2,n; for ( offset2 = 0; offset2 < counter->size; offset2++) { for (n = 1; n <= counter->n; n++) { word = counter->words[n-1][offset2] & ~counter->words[n][offset2]; word &= mask_words[offset2]; BITSET_POP_COUNT(counts[n-1], word); } } bitset_malloc_free(mask_words); return counts; }
void bitset_linear_free(bitset_linear_t *counter) { bitset_malloc_free(counter->words); bitset_malloc_free(counter); }
void bitset_countn_count_free(unsigned *counts) { bitset_malloc_free(counts); }
void bitset_vector_free(bitset_vector_t *vector) { bitset_malloc_free(vector->buffer); bitset_malloc_free(vector); }