/* creates a new counting bloom filter from a given scaling bloom filter, with count and id */ counting_bloom_t *new_counting_bloom_from_scale(scaling_bloom_t *bloom) { int i; long offset; double error_rate; counting_bloom_t *cur_bloom; error_rate = bloom->error_rate * (pow(ERROR_TIGHTENING_RATIO, bloom->num_blooms + 1)); if ((bloom->blooms = (counting_bloom_t **)realloc(bloom->blooms, (bloom->num_blooms + 1) * sizeof(counting_bloom_t *))) == NULL) { fprintf(stderr, "Error, could not realloc a new bloom filter\n"); return NULL; } cur_bloom = counting_bloom_init(bloom->capacity, error_rate, bloom->num_bytes); bloom->blooms[bloom->num_blooms] = cur_bloom; bloom->bitmap = bitmap_resize(bloom->bitmap, bloom->num_bytes, bloom->num_bytes + cur_bloom->num_bytes); /* reset header pointer, as mmap may have moved */ bloom->header = (scaling_bloom_header_t *) bloom->bitmap->array; /* Set the pointers for these header structs to the right location since mmap may have moved */ bloom->num_blooms++; for (i = 0; i < bloom->num_blooms; i++) { offset = bloom->blooms[i]->offset - sizeof(counting_bloom_header_t); bloom->blooms[i]->header = (counting_bloom_header_t *) (bloom->bitmap->array + offset); } bloom->num_bytes += cur_bloom->num_bytes; cur_bloom->bitmap = bloom->bitmap; return cur_bloom; }
/* * Create a new bitmap, not full featured, simple to give * us a means of interacting with the 4 bit counters. */ bitmap_t *new_bitmap(size_t bytes) { bitmap_t *bitmap; if ((bitmap = (bitmap_t *)malloc(sizeof(bitmap_t))) == NULL) { return NULL; } bitmap->bytes = bytes; bitmap->array = NULL; if ((bitmap = bitmap_resize(bitmap, 0, bytes)) == NULL) { return NULL; } return bitmap; }
void bitmap_copy(BITMAP *dest, BITMAP *src) { bitmap_resize(dest, src->width, src->height); memcpy(dest->buffer, src->buffer, src->stride * src->height); }