5
5
6
6
static bool recursiveTraverseGraph (Vertex * root ,Vertex * v ,int marker );
7
7
8
+ static Cluster cluster ;
9
+
8
10
void initGraph (Graph * graph )
9
11
{
10
12
memset (graph -> hashtable ,0 ,sizeof (graph -> hashtable ));
@@ -74,10 +76,28 @@ static inline Vertex* findVertex(Graph* graph, xid_t xid)
74
76
return v ;
75
77
}
76
78
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 )
78
97
{
79
98
xid_t * last = xids + n_xids ;
80
99
Edge * e ,* next ,* edges = NULL ;
100
+ Node * node = findNode (& cluster ,node_id );
81
101
while (xids != last ) {
82
102
Vertex * src = findVertex (graph ,* xids ++ );
83
103
xid_t xid ;
@@ -92,7 +112,7 @@ void addSubgraph(Instance* instance, Graph* graph, xid_t* xids, int n_xids)
92
112
l2_list_link (& src -> outgoingEdges ,& e -> node );
93
113
}
94
114
}
95
- for (e = instance -> edges ;e != NULL ;e = next ) {
115
+ for (e = node -> edges ;e != NULL ;e = next ) {
96
116
next = e -> next ;
97
117
l2_list_unlink (& e -> node );
98
118
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)
103
123
}
104
124
freeEdge (graph ,e );
105
125
}
106
- instance -> edges = edges ;
126
+ node -> edges = edges ;
107
127
}
108
128
109
129
static bool recursiveTraverseGraph (Vertex * root ,Vertex * v ,int marker )