123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475# 2 "stack.ml"(**************************************************************************)(* *)(* OCaml *)(* *)(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)(* *)(* Copyright 1996 Institut National de Recherche en Informatique et *)(* en Automatique. *)(* *)(* All rights reserved. This file is distributed under the terms of *)(* the GNU Lesser General Public License version 2.1, with the *)(* special exception on linking described in the file LICENSE. *)(* *)(**************************************************************************)open!Stdlib[@@@ocaml.flambda_o3]type('a:value_or_null)t={mutablec:'alist;mutablelen:int;}exceptionEmptyletcreate()={c=[];len=0;}letclears=s.c<-[];s.len<-0letcopys={c=s.c;len=s.len;}letpushxs=s.c<-x::s.c;s.len<-s.len+1letpops=matchs.cwith|hd::tl->s.c<-tl;s.len<-s.len-1;hd|[]->raiseEmptyletpop_opts=matchs.cwith|hd::tl->s.c<-tl;s.len<-s.len-1;Somehd|[]->Noneletdrops=matchs.cwith|_hd::tl->s.c<-tl;s.len<-s.len-1|[]->raiseEmptylettops=matchs.cwith|hd::_->hd|[]->raiseEmptylettop_opts=matchs.cwith|hd::_->Somehd|[]->Noneletis_emptys=(s.c=[])letlengths=s.lenletiterfs=List.iterfs.cletfoldfaccs=List.fold_leftfaccs.c(** {1 Iterators} *)letto_seqs=List.to_seqs.cletadd_seqqi=Seq.iter(funx->pushxq)iletof_seqg=lets=create()inadd_seqsg;s