123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134(**************************************************************************)(* *)(* 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). *)(* *)(**************************************************************************)(* -------------------------------------------------------------------------- *)(* --- Merging Set Functor --- *)(* -------------------------------------------------------------------------- *)moduletypeElt=sigtypetvalhash:t->intvalequal:t->t->boolvalcompare:t->t->intendmoduleMake(E:Elt)=structmoduleLset=Listset.Make(E)typeelt=E.ttypet=E.tlistIntmap.tlet_nonempty=function[]->None|l->Somelletis_emptyes=tryIntmap.iteri(fun_s->ifs<>[]thenraiseExit)es;truewithExit->falseletempty=Intmap.emptyletaddem=leth=E.hasheinletw=tryLset.adde(Intmap.findhm)withNot_found->[e]inIntmap.addhwmletsingletone=leth=E.hasheinIntmap.addh[e]Intmap.emptyletmemem=tryLset.meme(Intmap.find(E.hashe)m)withNot_found->falseletelementsm=Intmap.fold(funwxs->List.mergeE.comparewxs)m[]letiter_sortedfm=List.iterf(elementsm)letfold_sortedfma=List.fold_left(funaccx->fxacc)a(elementsm)(* good sharing *)letfilterfm=Intmap.mapq(fun_l->_nonempty(Lset.filterfl))m(* good sharing *)letremovekm=leth=E.hashkinIntmap.change(fun_hk->function|None->None|Someold->_nonempty(Lset.removekold))hkm(* good sharing *)letpartitionf=Intmap.partition_split(fun_kw->letu,v=Lset.partitionfwin(_nonemptyu),(_nonemptyv))exceptionBREAKletiterf=Intmap.iter(Lset.iterf)letfoldf=Intmap.fold(Lset.foldf)letfor_allfm=tryiter(funx->ifnot(fx)thenraiseBREAK)m;truewithBREAK->falseletexistsfm=tryiter(funx->iffxthenraiseBREAK)m;falsewithBREAK->true(* good sharing *)letdiff=Intmap.diffq(fun_hab->matchLset.diffabwith|[]->None|l->Somel)(* good sharing *)letunion=Intmap.union(fun_h->Lset.union)(* good sharing *)letinter=Intmap.inter(fun_h->Lset.inter)(* good sharing *)letsubset=Intmap.subset(fun_h->Lset.subset)letintersectm1m2=tryIntmap.iter2(fun_hxsys->matchxs,yswith|None,_|_,None->()|Somew1,Somew2->ifLset.intersectw1w2thenraiseExit)m1m2;falsewithExit->trueletequal=Intmap.equalLset.equalletcompare=Intmap.compareLset.compareletof_listl=List.fold_left(funacce->addeacc)emptylend