コード例 #1
0
/**
 * Shutdown task to cleanup our resources and exit.
 *
 * @param cls NULL
 * @param tc scheduler task context
 */
static void
do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
    if (NULL != transport)
    {
        GNUNET_TRANSPORT_disconnect (transport);
        transport = NULL;
    }
    cleanup_map ();
    unload_keys ();
    if (NULL != bh)
        GNUNET_TRANSPORT_blacklist_cancel (bh);
}
コード例 #2
0
ファイル: minimum.c プロジェクト: khsa1/cs691-project
int is_min(struct gspan *gs)
{
	GHashTable *projection_map;
	GList *l1, *l2, *edges, *values = NULL;
	struct pre_dfs *pm;
	struct dfs_code *first_key, *start_code;
	int ret;

	//printf("g_list_length(dfs_codes) = %d\n", g_list_length(gs->dfs_codes));
	if (g_list_length(gs->dfs_codes) == 1) {
		//printf("heremin1\n");
		return 1;
	}

	g_list_free(gs->min_dfs_codes);
	gs->min_dfs_codes = NULL;

	if (gs->min_graph)
		graph_free(gs->min_graph);
	//print_dfs_list(gs->dfs_codes);
	gs->min_graph = build_graph_dfs(gs->dfs_codes);

	projection_map = g_hash_table_new(dfs_code_hash, glib_dfs_code_equal);

	for (l1=g_list_first(gs->min_graph->nodes); l1; l1=g_list_next(l1)) {
		struct node *n = (struct node *)l1->data;

		edges = get_forward_init(n, gs->min_graph);

		if (g_list_length(edges) == 0) {
			g_list_free(edges);
			continue;
		}

		for (l2 = g_list_first(edges); l2; l2 = g_list_next(l2)) {
			struct edge *e = (struct edge *)l2->data;
			struct node *from_node, *to_node;
			struct dfs_code *dfsc;
			struct pre_dfs *npdfs;
#ifdef DEBUG
			print_edge(e);printf("\n");
#endif
			from_node = graph_get_node(gs->min_graph, e->from);
			to_node = graph_get_node(gs->min_graph, e->to);

			dfsc = malloc(sizeof(struct dfs_code));
			if (!dfsc) {
				perror("malloc dfsc in is_min");
				exit(1);
			}
			dfsc->from = 0;
			dfsc->to = 1;
			dfsc->from_label = from_node->label;
			dfsc->edge_label = e->label;
			dfsc->to_label = to_node->label;

			npdfs = malloc(sizeof(struct pre_dfs));
			if (!npdfs) {
				perror("malloc npdfs in is_min");
				exit(1);
			}
			npdfs->id = 0;
			npdfs->edge = e;
			npdfs->prev = NULL;

			if (g_hash_table_contains(projection_map, dfsc))
				values = g_hash_table_lookup(projection_map, 
									dfsc);
			values = g_list_append(values, npdfs);
			g_hash_table_insert(projection_map, dfsc, values);
			values = NULL;
		}

		//g_list_free(edges);
		//edges = NULL;
	}

	l2 = g_hash_table_get_keys(projection_map);
	l2 = g_list_sort(l2, (GCompareFunc)dfs_code_project_compare);
	first_key = (struct dfs_code *)g_list_first(l2)->data;
	g_list_free(l2);

	start_code = malloc(sizeof(struct dfs_code));
	if (!start_code) {
		perror("malloc start_code in is_min");
		exit(1);
	}
	start_code->from = 0;
	start_code->to = 1;
	start_code->from_label = first_key->from_label;
	start_code->edge_label = first_key->edge_label;
	start_code->to_label = first_key->to_label;

	gs->min_dfs_codes = g_list_append(gs->min_dfs_codes, start_code);
	//print_dfs(g_list_nth_data(gs->dfs_codes, 
	//				g_list_length(gs->min_dfs_codes)-1));
	//printf("\n");
	//print_dfs(g_list_last(gs->min_dfs_codes)->data);
	//printf("\n");
	if (!dfs_code_equal(
				g_list_nth_data(gs->dfs_codes, 
					g_list_length(gs->min_dfs_codes)-1), 
				g_list_last(gs->min_dfs_codes)->data)) {
#ifdef DEBUG
		printf("heremin2\n");
#endif
		return 0;
	}
	values = g_hash_table_lookup(projection_map, first_key);
	ret = projection_min(gs, values);
	
	cleanup_map(projection_map);
	//g_list_free(values);
	//printf("ret = %d\n", ret);
	return ret;
}
コード例 #3
0
ファイル: minimum.c プロジェクト: khsa1/cs691-project
static int projection_min(struct gspan *gs, GList *projection)
{
	GList *right_most_path, *l1, *keys, *values = NULL;
	int min_label;
	int ret;
	GHashTable *pm_backwards, *pm_forwards;

	right_most_path = build_right_most_path(gs->min_dfs_codes);
	min_label = ((struct dfs_code *)
			g_list_first(gs->min_dfs_codes)->data)->from_label;

	pm_backwards = g_hash_table_new(dfs_code_hash, glib_dfs_code_equal);
	pm_forwards = g_hash_table_new(dfs_code_hash, glib_dfs_code_equal);

	ret = judge_backwards(gs, right_most_path, projection, pm_backwards);

#ifdef DEBUG
	printf("jb %d ", ret);
#endif
	if (ret) {
		keys = g_hash_table_get_keys(pm_backwards);
		keys = g_list_sort(keys, (GCompareFunc)dfs_code_backward_compare);
#ifdef DEBUG
		print_dfs_list(keys);
		printf("\n");
#endif
		for (l1 = g_list_first(keys); l1; l1 = g_list_next(l1)) {
			struct dfs_code *dfsc = (struct dfs_code *)l1->data;

			gs->min_dfs_codes = g_list_append(gs->min_dfs_codes, 
									dfsc);
			if (!dfs_code_equal(
				g_list_nth_data(gs->dfs_codes, 
					g_list_length(gs->min_dfs_codes)-1), 
					g_list_last(gs->min_dfs_codes)->data)) {

				g_list_free(keys);
				cleanup_map(pm_backwards);
				cleanup_map(pm_forwards);
				g_list_free(right_most_path);
				return 0;
			}
		
			values = g_hash_table_lookup(pm_backwards, dfsc);
			ret = projection_min(gs, values);

			g_list_free(keys);
			cleanup_map(pm_backwards);
			cleanup_map(pm_forwards);
			g_list_free(right_most_path);
			return ret;
		}
		g_list_free(keys);
	} 
#ifdef DEBUG
	else {printf("\n");}
#endif
	
	ret = judge_forwards(gs, right_most_path, projection, 
						pm_forwards, min_label);
#ifdef DEBUG
	printf("jf %d", ret);
#endif
	if (ret) {
		keys = g_hash_table_get_keys(pm_forwards);
		keys = g_list_sort(keys, (GCompareFunc)dfs_code_forward_compare);
#ifdef DEBUG
		print_dfs_list(keys);
		printf("\n");
#endif
		for (l1 = g_list_first(keys); l1; l1 = g_list_next(l1)) {
			struct dfs_code *dfsc = (struct dfs_code *)l1->data;

			gs->min_dfs_codes = g_list_append(gs->min_dfs_codes, 
									dfsc);
			if (!dfs_code_equal(
				g_list_nth_data(gs->dfs_codes, 
					g_list_length(gs->min_dfs_codes)-1), 
					g_list_last(gs->min_dfs_codes)->data)) {

				g_list_free(keys);
				cleanup_map(pm_forwards);
				cleanup_map(pm_backwards);
				g_list_free(right_most_path);
				return 0;
			}
		
			values = g_hash_table_lookup(pm_forwards, dfsc);
			ret = projection_min(gs, values);

			g_list_free(keys);
			cleanup_map(pm_backwards);
			cleanup_map(pm_forwards);
			g_list_free(right_most_path);
			return ret;
		}
		g_list_free(keys);
	} 
#ifdef DEBUG
	else { printf("\n"); }
#endif
	g_list_free(right_most_path);
	cleanup_map(pm_backwards);
	cleanup_map(pm_forwards);
	return 1;
}