.TH "Queue" 3o source: 2019-08-06 OCamldoc "OCaml library" .SH NAME Queue \- First-in first-out queues. .SH Module Module Queue .SH Documentation .sp Module .BI "Queue" : .B sig end .sp First\-in first\-out queues\&. .sp This module implements queues (FIFOs), with in\-place modification\&. .sp Warning This module is not thread\-safe: each .B Queue\&.t value must be protected from concurrent access (e\&.g\&. with a .B Mutex\&.t )\&. Failure to do so can lead to a crash\&. .sp .sp .sp .I type .B 'a .I t .sp The type of queues containing elements of type .B \&'a \&. .sp .I exception Empty .sp Raised when .B Queue\&.take or .B Queue\&.peek is applied to an empty queue\&. .sp .I val create : .B unit -> 'a t .sp Return a new queue, initially empty\&. .sp .I val add : .B 'a -> 'a t -> unit .sp .B add x q adds the element .B x at the end of the queue .B q \&. .sp .I val push : .B 'a -> 'a t -> unit .sp .B push is a synonym for .B add \&. .sp .I val take : .B 'a t -> 'a .sp .B take q removes and returns the first element in queue .B q , or raises .B Queue\&.Empty if the queue is empty\&. .sp .I val pop : .B 'a t -> 'a .sp .B pop is a synonym for .B take \&. .sp .I val peek : .B 'a t -> 'a .sp .B peek q returns the first element in queue .B q , without removing it from the queue, or raises .B Queue\&.Empty if the queue is empty\&. .sp .I val top : .B 'a t -> 'a .sp .B top is a synonym for .B peek \&. .sp .I val clear : .B 'a t -> unit .sp Discard all elements from a queue\&. .sp .I val copy : .B 'a t -> 'a t .sp Return a copy of the given queue\&. .sp .I val is_empty : .B 'a t -> bool .sp Return .B true if the given queue is empty, .B false otherwise\&. .sp .I val length : .B 'a t -> int .sp Return the number of elements in a queue\&. .sp .I val iter : .B ('a -> unit) -> 'a t -> unit .sp .B iter f q applies .B f in turn to all elements of .B q , from the least recently entered to the most recently entered\&. The queue itself is unchanged\&. .sp .I val fold : .B ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b .sp .B fold f accu q is equivalent to .B List\&.fold_left f accu l , where .B l is the list of .B q \&'s elements\&. The queue remains unchanged\&. .sp .I val transfer : .B 'a t -> 'a t -> unit .sp .B transfer q1 q2 adds all of .B q1 \&'s elements at the end of the queue .B q2 , then clears .B q1 \&. It is equivalent to the sequence .B iter (fun x \-> add x q2) q1; clear q1 , but runs in constant time\&. .sp