1Queue(3)                         OCaml library                        Queue(3)
2
3
4

NAME

6       Queue - First-in first-out queues.
7

Module

9       Module   Queue
10

Documentation

12       Module Queue
13        : sig end
14
15
16       First-in first-out queues.
17
18       This module implements queues (FIFOs), with in-place modification.
19
20       Warning This module is not thread-safe: each Queue.t value must be pro‐
21       tected from concurrent access (e.g. with a Mutex.t ).  Failure to do so
22       can lead to a crash.
23
24
25
26
27
28       type 'a t
29
30
31       The type of queues containing elements of type 'a .
32
33
34
35       exception Empty
36
37
38       Raised when Queue.take or Queue.peek is applied to an empty queue.
39
40
41
42       val create : unit -> 'a t
43
44       Return a new queue, initially empty.
45
46
47
48       val add : 'a -> 'a t -> unit
49
50
51       add x q adds the element x at the end of the queue q .
52
53
54
55       val push : 'a -> 'a t -> unit
56
57
58       push is a synonym for add .
59
60
61
62       val take : 'a t -> 'a
63
64
65       take  q  removes  and  returns the first element in queue q , or raises
66       Queue.Empty if the queue is empty.
67
68
69
70       val take_opt : 'a t -> 'a option
71
72
73       take_opt q removes and returns the  first  element  in  queue  q  ,  or
74       returns None if the queue is empty.
75
76
77       Since 4.08
78
79
80
81       val pop : 'a t -> 'a
82
83
84       pop is a synonym for take .
85
86
87
88       val peek : 'a t -> 'a
89
90
91       peek  q returns the first element in queue q , without removing it from
92       the queue, or raises Queue.Empty if the queue is empty.
93
94
95
96       val peek_opt : 'a t -> 'a option
97
98
99       peek_opt q returns the first element in queue q , without  removing  it
100       from the queue, or returns None if the queue is empty.
101
102
103       Since 4.08
104
105
106
107       val top : 'a t -> 'a
108
109
110       top is a synonym for peek .
111
112
113
114       val clear : 'a t -> unit
115
116       Discard all elements from a queue.
117
118
119
120       val copy : 'a t -> 'a t
121
122       Return a copy of the given queue.
123
124
125
126       val is_empty : 'a t -> bool
127
128       Return true if the given queue is empty, false otherwise.
129
130
131
132       val length : 'a t -> int
133
134       Return the number of elements in a queue.
135
136
137
138       val iter : ('a -> unit) -> 'a t -> unit
139
140
141       iter  f  q  applies  f  in  turn  to all elements of q , from the least
142       recently entered to the most recently entered.   The  queue  itself  is
143       unchanged.
144
145
146
147       val fold : ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b
148
149
150       fold f accu q is equivalent to List.fold_left f accu l , where l is the
151       list of q 's elements. The queue remains unchanged.
152
153
154
155       val transfer : 'a t -> 'a t -> unit
156
157
158       transfer q1 q2 adds all of q1 's elements at the end of the queue q2  ,
159       then  clears q1 . It is equivalent to the sequence iter (fun x -> add x
160       q2) q1; clear q1 , but runs in constant time.
161
162
163
164
165   Iterators
166       val to_seq : 'a t -> 'a Seq.t
167
168       Iterate on the queue, in front-to-back  order.   The  behavior  is  not
169       defined if the queue is modified during the iteration.
170
171
172       Since 4.07
173
174
175
176       val add_seq : 'a t -> 'a Seq.t -> unit
177
178       Add the elements from the generator to the end of the queue
179
180
181       Since 4.07
182
183
184
185       val of_seq : 'a Seq.t -> 'a t
186
187       Create a queue from the generator
188
189
190       Since 4.07
191
192
193
194
195
196OCamldoc                          2020-09-01                          Queue(3)
Impressum