コード例 #1
0
ファイル: scope.cpp プロジェクト: bruce2008github/xocfe
SCOPE * new_scope()
{
    SCOPE * sc = (SCOPE*)xmalloc(sizeof(SCOPE));
	sc->init(g_scope_count);
	g_scope_list.append_tail(sc);
	return sc;
}
コード例 #2
0
ファイル: sgraph.cpp プロジェクト: bruce2008github/xocfe
//'order_buf': record the bfs-order for each vertex.
void DGRAPH::sort_in_bfs_order(SVECTOR<UINT> & order_buf, GRAPH & domtree,
							   VERTEX * root)
{		
	LIST<VERTEX*> worklst;
	worklst.append_tail(root);
	UINT order = 1;
	while (worklst.get_elem_count() > 0) {
		VERTEX * sv = worklst.remove_head();
		order_buf.set(VERTEX_id(sv), order);
		order++;
		EDGE_C * el = VERTEX_out_list(sv);
		while (el != NULL) {
			VERTEX * to = EDGE_to(EC_edge(el));
			worklst.append_tail(to);
			el = EC_next(el);
		}
	}
}
コード例 #3
0
ファイル: sgraph.cpp プロジェクト: bruce2008github/xocfe
//Reverse all edge direction
void GRAPH::rev_edges()
{
	IS_TRUE(m_pool != NULL, ("not yet initialized."));
	IS_TRUE(m_is_direction, ("graph is indirection"));
	LIST<EDGE*> list;
	EDGE * e;
	INT c;
	for (e = get_first_edge(c); e != NULL; e = get_next_edge(c)) {
		list.append_tail(e);		
	}
	for (e = list.get_head(); e != NULL; e = list.get_next()) { 
		rev_edge(e);
	}	
}
コード例 #4
0
ファイル: sgraph.cpp プロジェクト: bruce2008github/xocfe
/*
Sort graph vertices in topological order. 
'vex_vec': record nodes with topological sort.
NOTE: current graph will be empty at function return.
	If one need to keep the graph unchanged, clone graph
	as a tmpgraph and operate on the tmpgraph.
	e.g: GRAPH org; 
		And org must be unchanged, 
		GRAPH tmp(org);
		tmp.sort_in_toplog_order(...)	
*/
bool GRAPH::sort_in_toplog_order(OUT SVECTOR<UINT> & vex_vec, bool is_topdown)
{
	IS_TRUE(m_pool != NULL, ("Graph still not yet initialize."));
	if (get_vertex_num() == 0) {
		return true;
	}
	LIST<VERTEX*> vlst;
	UINT pos = 0;
	vex_vec.clean();
	vex_vec.grow(get_vertex_num());
	while (this->get_vertex_num() != 0) {
		vlst.clean();
		VERTEX * v;
		INT c;
		for (v = this->get_first_vertex(c);
			 v != NULL; v = this->get_next_vertex(c)) {
			if (is_topdown) {
				if (VERTEX_in_list(v) == NULL) {
					vlst.append_tail(v);
				}
			} else if (VERTEX_out_list(v) == NULL) {
				vlst.append_tail(v);				
			}
		}
		if (vlst.get_elem_count() == 0 && this->get_vertex_num() != 0) {
			IS_TRUE(0, ("exist cycle in graph"));
			return false;
		}
		for (v = vlst.get_head(); v != NULL; v = vlst.get_next()) {
			vex_vec.set(pos, VERTEX_id(v));
			pos++;
			this->remove_vertex(v);
		}
	}
	return true;
}