Exemple #1
0
int
main(int argc, char **argv)
{
  LST_STree     *tree;
  LST_String    *string = NULL;
  LST_StringSet *set;
  int i;
  
  if (argc < 2)
    test_usage(argv[0]);

  /* Create a string set to conveniently hold all our strings: */
  set = lst_stringset_new();

  /* Add all strings passed on the command line to the set.
   * Note that we pass the string length excluding the null
   * terminator, libstree handles that generically.
   */
  for (i = 1; i < argc; i++)
    {
      string = lst_string_new(argv[i], 1, strlen(argv[i]));
      lst_stringset_add(set, string);
    }

  /* Create a suffix tree for all strings in the set: */
  tree = lst_stree_new(set);
  fprintf(stderr, "Tree after all insertions:\n");
  lst_debug_print_tree(tree);

  /* Free suffix tree: */
  lst_stree_free(tree);

  return 0;
}
Exemple #2
0
static VALUE push(VALUE self, VALUE o)
{
    LST_STree * tree;

    Data_Get_Struct(self, LST_STree, tree);

    LST_String * string = lst_string_new(
                              StringValuePtr(o), sizeof(char), RSTRING_LEN(o));

    lst_stree_add_string(tree, string);

    return self;
}
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;
}
int main(int arg, char *argv) {

	char * str1 = "HTTP/1.1 index.html";
	char * str2 = "HTTP/1.0 aaaaa.html";
	char * str3 = "HTTP/1.0 bbbbb.html";
	char * str4 = "HTTP/1.1 ccccc.html";
	char * str5 = "HTTP/0.9 ddddd.html";
	char * str6 = "HTTP/1.1 fffff.html";
	char * str7 = "HTTP/0.9 eeeee.html";

	LST_String * nbytes1 = lst_string_new(str1, 1, strlen(str1));
	LST_String * nbytes2 = lst_string_new(str2, 1, strlen(str2));
	LST_String * nbytes3 = lst_string_new(str3, 1, strlen(str3));
	LST_String * nbytes4 = lst_string_new(str4, 1, strlen(str4));
	LST_String * nbytes5 = lst_string_new(str5, 1, strlen(str5));
	LST_String * nbytes6 = lst_string_new(str6, 1, strlen(str6));
	LST_String * nbytes7 = lst_string_new(str7, 1, strlen(str7));

	LST_StringSet * set = lst_stringset_new();
	lst_stringset_add(set, nbytes1);
	lst_stringset_add(set, nbytes2);
	lst_stringset_add(set, nbytes3);
	lst_stringset_add(set, nbytes4);
	lst_stringset_add(set, nbytes5);
	lst_stringset_add(set, nbytes6);
	lst_stringset_add(set, nbytes7);

	int first_bytes = 8;
	int last_bytes = 10;
	int num_bytes = 19;
	int gamma_merge = 2;

	product_distribution_t * pd = product_distribution_new(set, first_bytes, last_bytes, num_bytes);

	/* print pd */
	HashTableIterator iterator1;
	hash_table_iterate(pd->offset_distribution, &iterator1);

	while (hash_table_iter_has_more(&iterator1)){
		HashTablePair pair1 = hash_table_iter_next(&iterator1);
		
		int *key1 = (int *) pair1.key;
		byte_distribution_t *value1 = (byte_distribution_t *) pair1.value;

		HashTableIterator iterator2;
		hash_table_iterate(value1->value_frequency, &iterator2);
		if (hash_table_num_entries(value1->value_frequency) > gamma_merge) {
			continue;
		}
		printf("offset %d : ", *key1);	
		while(hash_table_iter_has_more(&iterator2)){
			HashTablePair pair2 = hash_table_iter_next(&iterator2);
			char *key2 = (char *) pair2.key;
			int *value2 = (int *) pair2.value;
			//printf("<%c, %d>\t", key2[0], *value2);
			if (0 == *key1) {
				printf("^%s\t", key2);
			} else if (num_bytes - 1 == *key1) {
				printf("%s$\t", key2);
			} else {
				printf("%s\t", key2);
			}
		}
		printf("\n");
	}

	product_distribution_free(pd);

	return 0;
}