1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950# 1 "src/batConcreteQueue_403.ml"[@@@warning"-37"](* Disable warning 37 (Unused constructor):
Cons is never used to build values,
but it is used implicitly in [of_abstr] *)type'acell=|Nil|Consof{content:'a;mutable next:'acell}type'at={mutablelength:int;mutablefirst:'acell;mutable last:'acell}external of_abstr:'aQueue.t->'at="%identity"externalto_abstr:'at->'aQueue.t="%identity"letfilter_inplacefqueue=(* find_next returns the next 'true' cell, or Nil *)letrecfind_next=function|Nil->Nil|(Conscell)ascons->iffcell.contentthenconselsefind_nextcell.nextin(* last is the last known 'true' Cons cell
(may be Nil if no true cell has be found yet)
next is the next candidate true cell
(may be Nil if there is no next cell) *)letreclooplengthlastnext=matchnextwith|Nil->(length,last)|(Conscell)ascons ->letnext=find_nextcell.nextincell.next<-next;loop(length +1)cons nextinletfirst=find_nextqueue.firstin(* returninga pair is unnecessary, the writes could be made at the
end of 'loop', but the present style makes it obvious that all
three writes are performed atomically, without allocation,
function call or return (yield points) in between, guaranteeing
some form of state consistency in the face of signals, threading
or what not. *)let(length,last)=loop0Nilfirstinqueue.length<-length;queue.first<-first;queue.last<-last;()