示例#1
0
/**
 * Creates a new filter and adds it to the filter map.
 * @arg mgr The manager to add to
 * @arg filter_name The name of the filter
 * @arg config The configuration for the filter
 * @arg is_hot Is the filter hot. False for existing.
 * @arg delta Is this a delta update or should the map be updated
 * @return 0 on success, -1 on error
 */
static int add_filter(bloom_filtmgr *mgr, char *filter_name, bloom_config *config, int is_hot, int delta) {
    // Create the filter
    bloom_filter_wrapper *filt = calloc(1, sizeof(bloom_filter_wrapper));
    filt->is_active = 1;
    filt->is_hot = is_hot;
    filt->should_delete = 0;
    pthread_rwlock_init(&filt->rwlock, NULL);

    // Set the custom filter if its not the same
    if (mgr->config != config) {
        filt->custom = config;
    }

    // Try to create the underlying filter. Only discover if it is hot.
    int res = init_bloom_filter(config, filter_name, is_hot, &filt->filter);
    if (res != 0) {
        free(filt);
        return -1;
    }

    // Check if we are adding a delta value or directly updating ART tree
    if (delta)
        create_delta_update(mgr, CREATE, filt);
    else
        art_insert(mgr->filter_map, (unsigned char*)filter_name, strlen(filter_name)+1, filt);
    return 0;
}
示例#2
0
void testBF() {
	/*FILE *fp;
	char dictionary_line[30];*/

	struct bloom_filter *bloom;
	bloom=NULL;

	bloom=init_bloom_filter(bloom);

	add_to_bloom_filter(bloom,"bob");
	add_to_bloom_filter(bloom,"tim");

	search_bloom_filter(bloom,"bob");
	search_bloom_filter(bloom,"alice");
	search_bloom_filter(bloom,"tim");
	search_bloom_filter(bloom,"Tim");

	/*fp = fopen("/usr/share/dict/american-english","r");
	while(fgets(dictionary_line,30,fp) != NULL) {
		add_to_bloom_filter(bloom,dictionary_line);
	}
	fclose(fp);

	search_bloom_filter(bloom,"Centrismmm@@@ZZZzz");*/
}