-
Notifications
You must be signed in to change notification settings - Fork 465
/
Copy pathbelt_MutableQueue.mli
95 lines (73 loc) · 3.42 KB
/
belt_MutableQueue.mli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
(**************************************************************************)
(* *)
(* 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. *)
(* *)
(**************************************************************************)
(* Adapted significantly by BuckleScript Authors *)
(** First-in first-out queues.
This module implements queues (FIFOs), with in-place modification.
*)
type 'a t
(** The type of queues containing elements of type ['a]. *)
val make: unit -> 'a t
(** @return a new queue, initially empty. *)
val clear: 'a t -> unit
(** Discard all elements from the queue. *)
val isEmpty: 'a t -> bool
(** @return [true] if the given queue is empty, [false] otherwise. *)
val fromArray: 'a array -> 'a t
(** [fromArray a] is equivalent to [Array.forEach a (add q a)] *)
val add: 'a t -> 'a -> unit
(** [add q x] adds the element [x] at the end of the queue [q]. *)
val peek: 'a t -> 'a option
(** [peekOpt q] returns the first element in queue [q], without removing
it from the queue. *)
val peekUndefined: 'a t -> 'a Js.undefined
(** [peekUndefined q] returns [undefined] if not found *)
val peekExn: 'a t -> 'a
(** [peekExn q]
{b raise} an exception if [q] is empty *)
val pop: 'a t -> 'a option
(** [pop q] removes and returns the first element in queue [q].*)
val popUndefined: 'a t -> 'a Js.undefined
(** [popUndefined q] removes and returns the first element in queue [q].
it will return undefined if it is already empty
*)
val popExn: 'a t -> 'a
(** [popExn q]
{b raise} an exception if [q] is empty
*)
val copy: 'a t -> 'a t
(** [copy q]
@return a fresh queue
*)
val size: 'a t -> int
(** @return the number of elements in a queue. *)
val mapU: 'a t -> ('a -> 'b [@bs]) -> 'b t
val map: 'a t -> ('a -> 'b ) -> 'b t
val forEachU: 'a t -> ('a -> unit [@bs]) -> unit
val forEach: 'a t -> ('a -> unit ) -> unit
(** [forEach q f] applies [f] in turn to all elements of [q],
from the least recently entered to the most recently entered.
The queue itself is unchanged. *)
val reduceU: 'a t -> 'b -> ('b -> 'a -> 'b [@bs]) -> 'b
val reduce: 'a t -> 'b -> ('b -> 'a -> 'b ) -> 'b
(** [reduce q accu f] is equivalent to [List.reduce l accu f],
where [l] is the list of [q]'s elements. The queue remains
unchanged. *)
val transfer: 'a t -> 'a t -> unit
(** [transfer q1 q2] adds all of [q1]'s elements at the end of
the queue [q2], then clears [q1]. It is equivalent to the
sequence [forEach (fun x -> add x q2) q1; clear q1], but runs
in constant time. *)
val toArray: 'a t -> 'a array
(** First added will be in the beginning of the array *)