123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133open!ImportincludeBlit_intfmoduletypeSequence_gen=sigtype'atvallength:_t->intendmoduleMake_gen(Src:Sequence_gen)(Dst:sigincludeSequence_genvalcreate_like:len:int->'aSrc.t->'atvalunsafe_blit:('aSrc.t,'at)blitend)=structletunsafe_blit=Dst.unsafe_blitletblit~src~src_pos~dst~dst_pos~len=Ordered_collection_common.check_pos_len_exn~pos:src_pos~len~total_length:(Src.lengthsrc);Ordered_collection_common.check_pos_len_exn~pos:dst_pos~len~total_length:(Dst.lengthdst);iflen>0thenunsafe_blit~src~src_pos~dst~dst_pos~len;;letblito~src?(src_pos=0)?(src_len=Src.lengthsrc-src_pos)~dst?(dst_pos=0)()=blit~src~src_pos~len:src_len~dst~dst_pos;;(* [sub] and [subo] ensure that every position of the created sequence is populated by
an element of the source array. Thus every element of [dst] below is well
defined. *)letsubsrc~pos~len=Ordered_collection_common.check_pos_len_exn~pos~len~total_length:(Src.lengthsrc);letdst=Dst.create_like~lensrciniflen>0thenunsafe_blit~src~src_pos:pos~dst~dst_pos:0~len;dst;;letsubo?(pos=0)?lensrc=subsrc~pos~len:(matchlenwith|Somei->i|None->Src.lengthsrc-pos);;endmoduleMake1(Sequence:sigincludeSequence_genvalcreate_like:len:int->'at->'atvalunsafe_blit:('at,'at)blitend)=Make_gen(Sequence)(Sequence)moduleMake1_generic(Sequence:Sequence1)=Make_gen(Sequence)(Sequence)moduleMake(Sequence:sigincludeSequencevalcreate:len:int->tvalunsafe_blit:(t,t)blitend)=structmoduleSequence=structtype'at=Sequence.topenSequenceletcreate_like~len_=create~lenletlength=lengthletunsafe_blit=unsafe_blitendincludeMake_gen(Sequence)(Sequence)endmoduleMake_distinct(Src:Sequence)(Dst:sigincludeSequencevalcreate:len:int->tvalunsafe_blit:(Src.t,t)blitend)=Make_gen(structtype'at=Src.topenSrcletlength=lengthend)(structtype'at=Dst.topenDstletlength=lengthletcreate_like~len_=create~lenletunsafe_blit=unsafe_blitend)moduleMake_to_string(T:sigtypetend)(To_bytes:S_distinctwithtypesrc:=T.twithtypedst:=bytes)=structopenTo_bytesletsubsrc~pos~len=Bytes0.unsafe_to_string~no_mutation_while_string_reachable:(subsrc~pos~len);;letsubo?pos?lensrc=Bytes0.unsafe_to_string~no_mutation_while_string_reachable:(subo?pos?lensrc);;end