1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192(**************************************************************************)(* *)(* 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). *)(* *)(**************************************************************************)(* -------------------------------------------------------------------------- *)(* --- Simple Caches --- *)(* -------------------------------------------------------------------------- *)moduletypeS=sigtypetvalhash:t->intvalequal:t->t->boolendmoduletypeCache=sigtype'avaluetype'acachevalcreate:size:int->'acachevalclear:'acache->unitvalcompute:'acache->'avalue->'avalueendletreclog2upnab=letc=(a+b)/2inlets=1lslcinifs=nthencelseifc=athenbelseifs<nthenlog2upncbelselog2upnacletmax_cache_log=log2upSys.max_array_length0(Sys.word_size-3)-1letallocsize=1lsl(log2upsize0max_cache_log)moduleUnary(A:S)=structtype'avalue=A.t->'atype'acell=N|CofA.t*'atype'acache='acellarrayletclearm=Array.fillm0(Array.lengthm)Nletcomputemfx=leth=A.hashxland(pred(Array.lengthm))inmatchm.(h)with|C(e,r)whenA.equalxe->r|_->letr=fxinm.(h)<-C(x,r);rletcreate~size=Array.make(allocsize)NendmoduleBinary(A:S)=structtype'avalue=A.t->A.t->'atype'acell=N|CofA.t*A.t*'atype'acache='acellarrayletclearm=Array.fillm0(Array.lengthm)Nletcomputemfxy=lets=Array.lengthminleth=(A.hashx*5+A.hashy*7)land(preds)inmatchm.(h)with|C(a,b,r)whenA.equalxa&&A.equalyb->r|_->letr=fxyinm.(h)<-C(x,y,r);rletcreate~size=Array.make(allocsize)Nend