1234567891011121314151617181920212223242526272829303132333435open!Importtypet={mutabledata:Bits.tarray;mutablelength:int}[@@derivingsexp_of,compare]letlengthd=d.lengthletgetdn=ifn<d.lengththend.data.(n)elseraise(Invalid_argument"wave out of bounds");;letcreate()={data=[||];length=0}letinitnf={data=Array.initn~f;length=n}letresized=letold_data=d.datainletnew_len=max1(Array.lengthd.data*2)ind.data<-Array.initnew_len~f:(funi->tryold_data.(i)with|_->Bits.gnd);;letrecsetdnv=tryd.data.(n)<-v;d.length<-maxd.length(n+1)with|_->resized;setdnv;;