12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970(******************************************************************************)(* *)(* Fix *)(* *)(* François Pottier, Inria Paris *)(* *)(* Copyright Inria. All rights reserved. This file is distributed under the *)(* terms of the GNU Library General Public License version 2, with a *)(* special exception on linking, as described in the file LICENSE. *)(* *)(******************************************************************************)openSigsmoduleMake(M:IMPERATIVE_MAPS)(G:GRAPHwithtypet=M.key)=struct(* Set up a facility for numbering vertices. *)moduleN=Numbering.Make(M)(* Implement a depth-first search. The functions [N.has_been_encoded]
and [N.encode] allow us not only to assign a unique number to each
vertex, but also to mark a vertex and test whether a vertex has been
marked. *)letfrontier=Stack.create()letpushx=Stack.pushxfrontierletrecvisit()=matchStack.popfrontierwith|exceptionStack.Empty->(* The stack is empty: we are done. *)()|x->ifN.has_been_encodedxthen(* [x] is known already: ignore it. *)visit()else(* Assign a number to [x]. *)let(_:int)=N.encodexinG.foreach_successorxpush;visit()(* Perform the depth-first search. *)let()=G.foreach_rootpush;visit()(* We are done! This defines [n], [encode], [decode]. *)includeN.Done()endmoduleForOrderedType(T:OrderedType)=Make(Glue.PersistentMapsToImperativeMaps(Map.Make(T)))moduleForHashedType(T:HashedType)=Make(Glue.HashTablesAsImperativeMaps(T))moduleForType(T:TYPE)=ForHashedType(Glue.TrivialHashedType(T))