12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485(**************************************************************************)(* *)(* 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: classic.ml,v 1.9 2004-02-02 08:11:14 filliatr Exp $ *)moduletypeS=sigtypegraphvaldivisors:int->graphvalde_bruijn:int->graphvalvertex_only:int->graphvalfull:?self:bool->int->graphendmoduleGeneric(B:Builder.INT)=structtypegraph=B.G.tletdivisorsn=ifn<2theninvalid_arg"divisors";letv=Array.init(n+1)(funi->B.G.V.createi)inletrecloopgi=letsqrt_i=truncate(sqrt(floati))inletrecloop_igd=ifd>sqrt_ithengelseifimodd==0thenloop_i(B.add_edge(B.add_edgegv.(i/d)v.(i))v.(d)v.(i))(d+1)elseloop_ig(succd)inifi>nthengelseloop(loop_i(B.add_vertexgv.(i))2)(i+1)inloop(B.empty())2letfold_fori0i1f=letrecloopiv=ifi>i1thenvelseloop(i+1)(fvi)inloopi0letde_bruijnn=ifn<1||n>Sys.word_size-1theninvalid_arg"de_bruijn";letv=Array.init(1lsln)(funi->B.G.V.createi)inletall_1=1lsln-1in(* 11...1 *)letg=fold_for0all_1(fungi->B.add_vertexgv.(i))(B.empty())inletrecloopgi=ifi>all_1thengelseletsi=(ilsl1)landall_1inletg=B.add_edgegv.(i)v.(si)inletg=B.add_edgegv.(i)v.(silor1)inloopg(i+1)inloopg0letvertex_onlyn=fold_for1n(fungi->B.add_vertexg(B.G.V.createi))(B.empty())letfull?(self=true)n=letv=Array.init(n+1)(funi->B.G.V.createi)infold_for1n(fungi->fold_for1n(fungj->ifself||i<>jthenB.add_edgegv.(i)v.(j)elseg)g)(fold_for1n(fungi->B.add_vertexgv.(i))(B.empty()))endmoduleP(G:Sig.PwithtypeV.label=int)=Generic(Builder.P(G))moduleI(G:Sig.IwithtypeV.label=int)=Generic(Builder.I(G))