Esempio n. 1
0
/**
 * @param set
 * @param first_bytes
 * @param last_bytes
 * @param num_bytes
 */
product_distribution_t * product_distribution_new(LST_StringSet * set, int first_bytes, int last_bytes, int num_bytes){

	if(!set) {
		return NULL;	
	}

	product_distribution_t * pd = (product_distribution_t *) malloc (sizeof(product_distribution_t));
	pd->first_bytes = first_bytes;
	pd->last_bytes = last_bytes;
	pd->num_bytes = num_bytes;
	pd->offset_distribution = hash_table_new(int_hash, int_equal);

	lst_stringset_foreach(set, calculate_product_distribution_callback, pd);

	return pd;	
}
int main(void){

	char * str1 = "HTTP/1.";
	char * str2 = "HTTP/1.0";
	char * str3 = "HTTP/1.1";
	char * str4 = "HTTP/1.1 20";
	char * str5 = "HTTP/1.1 30";
	char * str6 = "HTTP/1.1 40";
	char * str7 = "HTTP/1.0 20";
	char * str8 = "HTTP/1.0 30";
	
	LST_String * substring1 = lst_string_new(str1, 1, strlen(str1));
	LST_String * substring2 = lst_string_new(str2, 1, strlen(str2));
	LST_String * substring3 = lst_string_new(str3, 1, strlen(str3));
	LST_String * substring4 = lst_string_new(str4, 1, strlen(str4));
	LST_String * substring5 = lst_string_new(str5, 1, strlen(str5));
	LST_String * substring6 = lst_string_new(str6, 1, strlen(str6));
	LST_String * substring7 = lst_string_new(str7, 1, strlen(str7));
	LST_String * substring8 = lst_string_new(str8, 1, strlen(str8));

	LST_StringSet *substrings = lst_stringset_new();

	lst_stringset_add(substrings, substring1);
	lst_stringset_add(substrings, substring2);
	lst_stringset_add(substrings, substring3);
	lst_stringset_add(substrings, substring4);
	lst_stringset_add(substrings, substring5);
	lst_stringset_add(substrings, substring6);
	lst_stringset_add(substrings, substring7);
	lst_stringset_add(substrings, substring8);

	merge_common_prefix_main(substrings);

	if(set) {
		printf("set->size : %d\n", set->size);
		lst_stringset_foreach(set, string_cb, "\n");
	}


	return 0;
}