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