Library
Module
Module type
Parameter
Class
Class type
Functional queues
type 'a klist = unit -> [ `Nil | `Cons of 'a * 'a klist ]
type 'a printer = Format.formatter -> 'a -> unit
Basics
val empty : 'a t
val is_empty : 'a t -> bool
val singleton : 'a -> 'a t
val doubleton : 'a -> 'a -> 'a t
Same as take_front
, but fails on empty queues.
take_front_l n q
takes at most n
elements from the front of q
, and returns them wrapped in a list.
take_back_l n q
removes and returns the last n
elements of q
. The elements are in the order of the queue, that is, the head of the returned list is the first element to appear via take_front
. take_back_l 2 (of_list [1;2;3;4]) = of_list [1;2], [3;4]
.
Individual extraction
val first : 'a t -> 'a option
First element of the queue.
val last : 'a t -> 'a option
Last element of the queue.
val last_exn : 'a t -> 'a
val nth : int -> 'a t -> 'a option
Return the i
-th element of the queue in logarithmic time.
Global Operations
Append two queues. Elements from the second one come after elements of the first one. Linear in the size of the second queue.
val size : 'a t -> int
Number of elements in the queue (constant time).
val fold : ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b
val iter : ('a -> unit) -> 'a t -> unit
Conversions
val of_list : 'a list -> 'a t
val to_list : 'a t -> 'a list
val (--) : int -> int -> int t
a -- b
is the integer range from a
to b
, both included.
val (--^) : int -> int -> int t
a -- b
is the integer range from a
to b
, where b
is excluded.