55
66static bool recursiveTraverseGraph (Vertex * root , Vertex * v , int marker );
77
8+ static Cluster cluster ;
9+
810void initGraph (Graph * graph )
911{
1012 memset (graph -> hashtable , 0 , sizeof (graph -> hashtable ));
@@ -74,10 +76,28 @@ static inline Vertex* findVertex(Graph* graph, xid_t xid)
7476 return v ;
7577}
7678
77- void addSubgraph (Instance * instance , Graph * graph , xid_t * xids , int n_xids )
79+ static inline Node * findNode (Cluster * cluster , nodeid_t node_id )
80+ {
81+ size_t h = node_id % MAX_STREAMS ;
82+ Node * node ;
83+ for (node = cluster -> hashtable [h ]; node != NULL ; node = node -> collision ) {
84+ if (node -> node_id == node_id ) {
85+ return node ;
86+ }
87+ }
88+ node = (Node * )malloc (sizeof (Node ));
89+ node -> node_id = node_id ;
90+ node -> edges = NULL ;
91+ node -> collision = cluster -> hashtable [h ];
92+ cluster -> hashtable [h ] = node ;
93+ return node ;
94+ }
95+
96+ void addSubgraph (Graph * graph , nodeid_t node_id , xid_t * xids , int n_xids )
7897{
7998 xid_t * last = xids + n_xids ;
8099 Edge * e , * next , * edges = NULL ;
100+ Node * node = findNode (& cluster , node_id );
81101 while (xids != last ) {
82102 Vertex * src = findVertex (graph , * xids ++ );
83103 xid_t xid ;
@@ -92,7 +112,7 @@ void addSubgraph(Instance* instance, Graph* graph, xid_t* xids, int n_xids)
92112 l2_list_link (& src -> outgoingEdges , & e -> node );
93113 }
94114 }
95- for (e = instance -> edges ; e != NULL ; e = next ) {
115+ for (e = node -> edges ; e != NULL ; e = next ) {
96116 next = e -> next ;
97117 l2_list_unlink (& e -> node );
98118 if (-- e -> dst -> nIncomingEdges == 0 && l2_list_is_empty (& e -> dst -> outgoingEdges )) {
@@ -103,7 +123,7 @@ void addSubgraph(Instance* instance, Graph* graph, xid_t* xids, int n_xids)
103123 }
104124 freeEdge (graph , e );
105125 }
106- instance -> edges = edges ;
126+ node -> edges = edges ;
107127}
108128
109129static bool recursiveTraverseGraph (Vertex * root , Vertex * v , int marker )
0 commit comments