1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071(**************************************************************************)(* *)(* Ocamlgraph: a generic graph library for OCaml *)(* Copyright (C) 2004-2010 *)(* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *)(* *)(* This software is free software; you can redistribute it and/or *)(* modify it under the terms of the GNU Library General Public *)(* License version 2.1, with the special exception on linking *)(* described in file LICENSE. *)(* *)(* This software is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *)(* *)(**************************************************************************)(* $Id: kruskal.ml,v 1.5 2005-06-30 10:48:55 filliatr Exp $ *)moduletypeUNIONFIND=sigtypeelttypetvalinit:eltlist->tvalfind:elt->t->eltvalunion:elt->elt->t->unitendmoduletypeG=sigtypetmoduleV:Sig.COMPARABLEmoduleE:sigtypettypelabelvallabel:t->labelvaldst:t->V.tvalsrc:t->V.tendvalfold_vertex:(V.t->'a->'a)->t->'a->'avaliter_edges_e:(E.t->unit)->t->unitendmoduleGeneric(G:G)(W:Sig.ORDERED_TYPEwithtypet=G.E.label)(UF:UNIONFINDwithtypeelt=G.V.t)=structletspanningtreeg=letvertices=G.fold_vertex(funva->v::a)g[]inletuf=UF.initverticesinletedges=letl=ref[]inG.iter_edges_e(fune->l:=e::!l)g;List.sort(funee'->W.compare(G.E.labele)(G.E.labele'))!linlets=ref[]inletcovere=letu,v=G.E.srce,G.E.dsteinifG.V.compare(UF.finduuf)(UF.findvuf)<>0thenbeginUF.unionuvuf;s:=e::!sendinList.itercoveredges;!sendmoduleMake(G:G)(W:Sig.ORDERED_TYPEwithtypet=G.E.label)=Generic(G)(W)(Unionfind.Make(G.V))