aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/cycle_detection.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/cycle_detection.c b/src/cycle_detection.c
index 8dd5691..6f6c9af 100644
--- a/src/cycle_detection.c
+++ b/src/cycle_detection.c
@@ -33,16 +33,16 @@ void cycle_detection(Graph *g) {
// Compute in-degrees
for (int i = 0; i < n; i++) {
for (int j = 0; j < (int)g->vertices[i].out_neighbours->size; j++) {
- int neighbor = *(int *)g->vertices[i].out_neighbours->data[j];
- indegree[neighbor]++;
+ Vertex neighbor = *(Vertex *)
+ g->vertices[i].out_neighbours->data[j];
+ indegree[neighbor.id]++;
}
}
// Add all vertices with no incoming edges
for (int i = 0; i < n; i++) {
- if (indegree[i] == 0) {
+ if (indegree[i] == 0)
linked_list_append(queue, (void *)(intptr_t)i);
- }
}
// Process queue for topological sort
@@ -52,11 +52,11 @@ void cycle_detection(Graph *g) {
// Process all neighbors of current vertex
for (int j = 0; j < (int)g->vertices[top].out_neighbours->size; j++) {
- int neighbor = *(int *)g->vertices[top].out_neighbours->data[j];
- indegree[neighbor]--;
- if (!indegree[neighbor]) {
- linked_list_append(queue, (void *)(intptr_t)neighbor);
- }
+ Vertex neighbor = *(Vertex *)
+ g->vertices[top].out_neighbours->data[j];
+ indegree[neighbor.id]--;
+ if (!indegree[neighbor.id])
+ linked_list_append(queue, (void *)(intptr_t)neighbor.id);
}
}