123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990(* This file is free software, part of containers. See file "license" for more details. *)(** {1 Hash combinators} *)typehash=inttype'at='a->hashtype'asequence=('a->unit)->unittype'agen=unit->'aoptiontype'aklist=unit->[`Nil|`Consof'a*'aklist]letcombinefsx=Hashtbl.seeded_hashs(fx)letcombine2ab=Hashtbl.seeded_hashabletcombine3abc=combine2(combine2ab)cletcombine4abcd=combine2(combine2ab)(combine2cd)letcombine5abcde=combine2(combine2ab)(combine2(combine2cd)e)letcombine6abcdef=combine2(combine2ab)(combine2(combine2cd)(combine2ef))(** {2 Combinators} *)letconsth_=hletconst0_=0letinti=ilandmax_intletboolb=ifbthen1else2letcharx=Char.codexletint32(x:int32)=Hashtbl.hashxletint64(x:int64)=Hashtbl.hashxletnativeint(x:nativeint)=Hashtbl.hashxletstring(x:string)=Hashtbl.hashxletslicexilen=letj=i+leninletrecauxis=ifi=jthenselseaux(i+1)(combine2(charx.[i])s)inauxi0letoptf=function|None->42|Somex->combine243(fx)letlistfl=List.fold_left(combinef)0x42lletarrayfl=Array.fold_left(combinef)0x42lletpairfg(x,y)=combine2(fx)(gy)lettriplefgh(x,y,z)=combine2(combine2(fx)(gy))(hz)letquadfghi(x,y,z,w)=combine2(combine2(fx)(gy))(combine2(hz)(iw))letif_bthen_else_h=ifbthenthen_helseelse_hletpolyx=Hashtbl.hashxletarray_commfa=letarr=Array.init(Array.lengtha)(funi->fa.(i))inArray.sortCCInt.comparearr;(* sort the hashes, so their order does not matter *)array(funh->h)arrletlist_commfl=leta=Array.of_listlinarray_commfaletseqfseq=leth=ref0x43inseq(funx->h:=combinef!hx);!hletgenfg=letrecauxs=matchg()with|None->s|Somex->aux(combine2s(fx))inaux0x42letklistfl=letrecauxls=matchl()with|`Nil->s|`Cons(x,tail)->auxtail(combine2s(fx))inauxl0x42