- Please note that sorting on weight is already done by add_edge().
-*/
-
-void mst_kruskal(void) {
- splay_node_t *node, *next;
- edge_t *e;
- node_t *n;
- connection_t *c;
-
- /* Clear MST status on connections */
-
- for(node = connection_tree->head; node; node = node->next) {
- c = node->data;
- c->status.mst = false;
- }
-
- ifdebug(SCARY_THINGS) logger(LOG_DEBUG, "Running Kruskal's algorithm:");
-
- /* Clear visited status on nodes */
-
- for(node = node_tree->head; node; node = node->next) {
- n = node->data;
- n->status.visited = false;
- }
-
- /* Add safe edges */
-
- for(node = edge_weight_tree->head; node; node = next) {
- next = node->next;
- e = node->data;
-
- if(!e->reverse || (e->from->status.visited && e->to->status.visited))
- continue;
-
- e->from->status.visited = true;
- e->to->status.visited = true;
-
- if(e->connection)
- e->connection->status.mst = true;
-
- if(e->reverse->connection)
- e->reverse->connection->status.mst = true;
-
- ifdebug(SCARY_THINGS) logger(LOG_DEBUG, " Adding edge %s - %s weight %d", e->from->name,
- e->to->name, e->weight);
- }
-}
-
-/* Implementation of Dijkstra's algorithm.
- Running time: O(N^2)