예제 #1
0
int main()
{
	mapreduce_t mr;
	mapreduce_init(&mr, map, reduce);

	char *values[5];
	values[0] = "Two roads diverged in a yellow wood,";
	values[1] = "And sorry I could not travel both";
	values[2] = "And be one traveler, long I stood";
	values[3] = "And looked down one as far as I could.";
	values[4] = NULL;

	mapreduce_map_all(&mr, (const char **)values);
	mapreduce_reduce_all(&mr);

	char s[2]; s[1] = '\0';
	int i;
	for (i = 0; i < 26; i++)
	{
		s[0] = (i + 'a');

		const char *s1 = mapreduce_get_value(&mr, s);

		if (s1 == NULL)
			printf("%s: (null)\n", s);
		else
			printf("%s: %s\n", s, s1);
	}



	mapreduce_destroy(&mr);

	return 0;
}
예제 #2
0
int main()
{
	mapreduce_t mr;
	mapreduce_init(&mr, map, reduce);

	char *values[5];
	values[0] = "1";
	values[1] = "2";
	values[2] = "3";
	values[3] = "4";
	values[4] = NULL;

	mapreduce_map_all(&mr, (const char **)values);

	int i;
	for (i = 0; i < 10; i++)
	{
		const char *value = mapreduce_get_value(&mr, "value");
		if (value == NULL) { printf("value: (null)\n"); }
		else { printf("value: %s\n", value); free((void *)value); }
		sleep(1);
	}

	mapreduce_reduce_all(&mr);
	mapreduce_destroy(&mr);

	return 0;
}
예제 #3
0
int main() {
	FILE *file = fopen("alice.txt", "r");
	char s[1024];
	int i;

	char **values = malloc(INPUTS_NEEDED * sizeof(char *));
	int values_cur = 0;

	values[0] = malloc(CHARS_PER_INPUT + 1);
	values[0][0] = '\0';

	while (fgets(s, 1024, file) != NULL) {
		if (strlen(values[values_cur]) + strlen(s) < CHARS_PER_INPUT)
			strcat(values[values_cur], s);
		else {
			values_cur++;
			values[values_cur] = malloc(CHARS_PER_INPUT + 1);
			values[values_cur][0] = '\0';
			strcat(values[values_cur], s);
		}
	}

	values_cur++;
	values[values_cur] = NULL;

	fclose(file);

	mapreduce_t mr;
	mapreduce_init(&mr, map, reduce);

	mapreduce_map_all(&mr, (const char **) values);
	mapreduce_reduce_all(&mr);

	const char *result_longest = mapreduce_get_value(&mr, long_key);

	if (result_longest == NULL) {
		printf("MapReduce returned (null).  The longest word was not found.\n");
	} else {
		printf("Longest Word: %s\n", result_longest);
		free((void *) result_longest);
	}

	mapreduce_destroy(&mr);

	for (i = 0; i < values_cur; i++)
		free(values[i]);
	free(values);

	return 0;
}
예제 #4
0
파일: test2.c 프로젝트: cliu78/NoSQL-Client
int main(int argc, char **argv)
{

#ifdef LIBDS_NOSQL
	if (argc != 3)
		print_usage(argv);

	int port = atoi(argv[2]);
	if (port <= 0 || port >= 65536)
		print_usage(argv);

	datastore_set_server(argv[1], port);
#endif

	printf("Test Case: map() will produce the key-value \"A: 1\" 10,000 times in two map processes (20,000 times total). "
		   "The reduce() operation will sum \"A\", but will purposefully take a long time to finish. "
		   "This test case will never exit, use Ctrl+C to exit. "
		   "(This case should be useful to run in multiple shells to see if your MapReduce is correctly updating across multiple instances.)\n");

	mapreduce_t mr;
	mapreduce_init(&mr, map, reduce);

	char *values[3];
	values[0] = "1";
	values[1] = "2";
	values[2] = NULL;
	mapreduce_map_all(&mr, (const char **)values);

	while (1)
	{
		const char *s = "A";
		const char *s1 = mapreduce_get_value(&mr, s);

		if (s1 == NULL)
			printf("%s: (null)\n", s);
		else
			printf("%s: %s\n", s, s1);

		sleep(1);
	}

	mapreduce_reduce_all(&mr);
	mapreduce_destroy(&mr);
	return 0;
}
예제 #5
0
int main()
{
	mapreduce_t mr;
	mapreduce_init(&mr, map, reduce);
	char *values[2];
	values[0] = "Some text";
	values[1] = NULL;
	mapreduce_map_all(&mr, (const char **)values);
	mapreduce_reduce_all(&mr);

	const char *s = "letters";
	const char *s1 = mapreduce_get_value(&mr, s);
	if (s1 == NULL)
		printf("%s: (null)\n", s);
	else
	{
		printf("%s: %s\n", s, s1);
		free((void *)s1);
	}


	mapreduce_destroy(&mr);
	return 0;
}
예제 #6
0
int main()
{
	FILE *file = fopen("alice.txt", "r");
	char s[1024];
	int i;

	char **values = malloc(INPUTS_NEEDED * sizeof(char *));
	int values_cur = 0;

	values[0] = malloc(CHARS_PER_INPUT + 1);
	values[0][0] = '\0';

	while (fgets(s, 1024, file) != NULL)
	{
		if (strlen(values[values_cur]) + strlen(s) < CHARS_PER_INPUT)
			strcat(values[values_cur], s);
		else
		{
			values_cur++;
			values[values_cur] = malloc(CHARS_PER_INPUT + 1);
			values[values_cur][0] = '\0';
			strcat(values[values_cur], s);
		}
	}

	values_cur++;
	values[values_cur] = NULL;

	fclose(file);




	mapreduce_t mr;
	mapreduce_init(&mr, map, reduce);

	mapreduce_map_all(&mr, (const char **)values);
	mapreduce_reduce_all(&mr);


	const char *result_the = mapreduce_get_value(&mr, "the");
	const char *result_and = mapreduce_get_value(&mr, "and");
	const char *result_alice = mapreduce_get_value(&mr, "alice");
	const char *result_nonexist = mapreduce_get_value(&mr, "some-word-that-wont-exist");

	if (result_the == NULL) { printf("the: (null)\n"); }
	else { printf("the: %s\n", result_the); free((void *)result_the); }

	if (result_and == NULL) { printf("and: (null)\n"); }
	else { printf("and: %s\n", result_and); free((void *)result_and); }

	if (result_alice == NULL) { printf("alice: (null)\n"); }
	else { printf("alice: %s\n", result_alice); free((void *)result_alice); }

	if (result_nonexist == NULL) { printf("some-word-that-wont-exist: (null)\n"); }
	else { printf("some-word-that-wont-exist: %s\n", result_nonexist); free((void *)result_nonexist); }


	mapreduce_destroy(&mr);

	for (i = 0; i < values_cur; i++)
		free(values[i]);
	free(values);


	return 0;
}