123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124(**************************************************************************)(* *)(* This file is part of WP plug-in of Frama-C. *)(* *)(* Copyright (C) 2007-2023 *)(* CEA (Commissariat a l'energie atomique et aux energies *)(* alternatives) *)(* *)(* you can redistribute it and/or modify it under the terms of the GNU *)(* Lesser General Public License as published by the Free Software *)(* Foundation, version 2.1. *)(* *)(* It 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. See the *)(* GNU Lesser General Public License for more details. *)(* *)(* See the GNU Lesser General Public License version 2.1 *)(* for more details (enclosed in the file licenses/LGPLv2.1). *)(* *)(**************************************************************************)(* -------------------------------------------------------------------------- *)(* --- Hash Consing Utilities --- *)(* -------------------------------------------------------------------------- *)letprimes=[|2;3;5;7;11;13;17;19;23;29;31;37;41;43;47;53;59;61;67;71;73;79;83;89;97;101;103;107;109;113;127;131;137;139;149;151;157;163;167;173;179;181;191;193;197;199;211;223;227;229;233;239;241;251;257;263;269;271;277;281|]letn_primes=Array.lengthprimeslethash_intt=ift<n_primesthenprimes.(t)else1lethash_tagx=hash_int(Obj.tag(Obj.reprx))lethash_pairxy=x*599+y*799lethash_triplexyz=x*281+y*599+z*799letrechash_listfh=function|[]->h|x::xs->hash_listf(h*599+fx)xslethash_optfh=function|None->h|Somex->h*281+fxlethash_arrayfhxs=letreccollecthxsi=ifi<Array.lengthxsthencollect(h*599+fxs.(i))xs(succi)elsehincollecthxs0letreccompare_listcmpxsys=ifxs==ysthen0elsematchxs,yswith|[],[]->0|[],_::_->-1|_::_,[]->1|x::xs,y::ys->letc=cmpxyinifc=0thencompare_listcmpxsyselsecletrecequal_listeqxsys=xs==ys||matchxs,yswith|[],[]->true|[],_::_|_::_,[]->false|x::xs,y::ys->eqxy&&equal_listeqxsysletequal_arrayeqxsys=letn=Array.lengthxsinletm=Array.lengthysinn=m&&begintryfori=0ton-1doifnot(eqxs.(i)ys.(i))thenraiseExitdone;truewithExit->falseendletexists_arrayfxs=tryfori=0toArray.lengthxs-1doiffxs.(i)thenraiseExitdone;falsewithExit->trueletforall_arrayfxs=tryfori=0toArray.lengthxs-1doifnot(fxs.(i))thenraiseExitdone;truewithExit->falseletreceq_listxsys=matchxs,yswith|[],[]->true|[],_::_|_::_,[]->false|x::xs,y::ys->x==y&&eq_listxsysleteq_arrayxsys=letn=Array.lengthxsinletm=Array.lengthysinn=m&&begintryfori=0ton-1doifnot(xs.(i)==ys.(i))thenraiseExitdone;truewithExit->falseendletrecfold_listopfa=function|[]->a|x::xs->fold_listopf(opa(fx))xsletfold_arrayopfaxs=letreccollectopfaxsi=ifi<Array.lengthxsthencollectopf(opa(fxs.(i)))xs(succi)elseaincollectopfaxs0