123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113(* This file is free software, part of Zipperposition. See file "license" for more details. *)(** {1 Immutable Arrays} *)type'aequal='a->'a->booltype'aord='a->'a->inttype'at='aarrayletof_list=Array.of_listletto_list=Array.to_listletto_array_copy=Array.copyletto_array_unsafea=aletof_array_unsafea=a(* bleh. *)letempty=[||]letlength=Array.lengthletsingletonx=[|x|]letdoubletonxy=[|x;y|]letmakenx=Array.makenxletinitnf=Array.initnfletget=Array.getletsetanx=leta'=Array.copyaina'.(n)<-x;a'letmap=Array.mapletmap_arr=Array.mapletmapi=Array.mapiletmapi_arr=Array.mapiletappendab=letna=lengthainArray.init(na+lengthb)(funi->ifi<nathena.(i)elseb.(i-na))letiter=Array.iterletiteri=Array.iteriletfold=Array.fold_leftletfoldifacca=letn=ref0inArray.fold_left(funaccx->letacc=facc!nxinincrn;acc)accaexceptionExitNowletfor_allpa=tryArray.iter(funx->ifnot(px)thenraiseExitNow)a;truewithExitNow->falseletexistspa=tryArray.iter(funx->ifpxthenraiseExitNow)a;falsewithExitNow->trueletequaleqab=letrecauxi=ifi=Array.lengthathentrueelseeqa.(i)b.(i)&&aux(i+1)inArray.lengtha=Array.lengthb&&aux0letcomparecmpab=letrecauxi=ifi=Array.lengthathenifi=Array.lengthbthen0else-1elseifi=Array.lengthbthen1elseletc=cmpa.(i)b.(i)inifc=0thenaux(i+1)elsecinaux0letto_iterak=iterkaletto_iteriak=iteri(funix->k(i,x))aletof_iters=letl=ref[]ins(funx->l:=x::!l);Array.of_list(List.rev!l)lethashfa=Hash.arrayfalethash_commfa=letarr=Array.init(Array.lengtha)(funi->fa.(i))inArray.sortCCInt.comparearr;(* sort the hashes, so their order does not matter *)Hash.array(funh->h)arr