Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file table.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103(**************************************************************************)(* *)(* ACG development toolkit *)(* *)(* Copyright 2008-2021 INRIA *)(* *)(* More information on "http://acg.gforge.inria.fr/" *)(* License: CeCILL, see the LICENSE file or "http://www.cecill.info" *)(* Authors: see the AUTHORS file *)(* *)(* *)(* *)(* *)(* $Rev:: $: Revision of last commit *)(* $Author:: $: Author of last commit *)(* $Date:: $: Date of last commit *)(* *)(**************************************************************************)moduletypeBASE=sigvalb:intendmoduletypeTABLE=sigexceptionNot_foundexceptionConflicttype'attypekeyvalempty:'atvaladd:?overwrite:bool->key->'a->'at->'atvalfind:key->'at->'avalfold:(key->'a->'b->'b)->'b->'at->'bendmoduleMake_table(Base:BASE)=structexceptionNot_foundexceptionConflicttype'at=Nil|Tof('aoption*'at)arraytypekey=int(* let create () = T (Array.create Base.b (None, Nil)) *)letcreate()=T(Array.makeBase.b(None,Nil))letempty=Nilletadd?(overwrite=false)nattrtable=letrecinsert1ntable=matchtablewithNil->insert1n(create())|Tar->let(r,i)=(n/Base.b,nmodBase.b)inlet(a,tb)=ar.(i)inifr=0thenmatcha,overwritewith|None,_->ar.(i)<-(Someattr,tb);Tar|Some_,false->raiseConflict|Some_,true->ar.(i)<-(Someattr,tb);Tarelse(ar.(i)<-(a,insert1rtb);Tar)ininsert1ntableletrecfindntable=matchtablewithNil->raiseNot_found|Tar->let(r,i)=(n/Base.b,nmodBase.b)inlet(a,tb)=ar.(i)inifr=0thenmatchawithNone->raiseNot_found|Someb->belsefindrtbletfoldfacctable=letrecfold_auxqacc=function|Nil->acc|Tar->let_,new_acc=Array.fold_left(fun(i,acc)->function|Somev,_->i+1,f(q*Base.b+i)vacc|None,_->i+1,acc)(0,acc)arinsnd(Array.fold_left(fun(i,acc)(_,t)->i+1,fold_aux(q+1)acct)(0,new_acc)ar)infold_aux0acctableend